Android view 绘制-/绘制圆点/空心圆/圆角/只要顶部两个角为圆角的矩形

绘制圆点

绘制圆点 目录结构D:\androidWorks\xxx\app\src\main\res\drawable\rounddot.xml

参考:https://blog.csdn.net/g984160547/article/details/70257839 Android Shape常用

绘制
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="@color/white" />
    <size
        android:width="5dp"
        android:height="5dp" />
</shape>
使用
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/dimen_10_dip"
    android:layout_marginRight="@dimen/dimen_15_dip"
    android:src="@drawable/hollow_circle" />

绘制虚线

绘制虚线 目录结构D:\androidWorks\swp\app\src\main\res\drawable\dashed_line.xml

参考:https://blog.csdn.net/g984160547/article/details/70257839 Android Shape常用

绘制
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">
    <stroke
        android:width="@dimen/dimen_1_dip"
        android:color="@color/black"
        android:dashWidth="@dimen/dimen_1_dip"
        android:dashGap="@dimen/dimen_5_dip" />
    <!--width 虚线点的高度-->
    <!--dashWidth 虚线点的宽度-->
    <!--dashGap 虚线点的间隔-->
</shape>
使用
<View
    android:layout_width="match_parent"
    android:layout_height="@dimen/dimen_2_dip"
    android:background="@drawable/dashed_line"
    android:layerType="software" 
    android:layout_marginRight="@dimen/dimen_10_dip"
    android:layout_marginLeft="@dimen/dimen_10_dip"/>
    <!--android:layerType="software" 这句话要加上不然android 4.0 的真机会显示成实线-->

空心圆

空心圆 目录结构D:\androidWorks\swp\app\src\main\res\drawable\hollow_circle.xml
绘制
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval"
    android:useLevel="false">
    <stroke
        android:width="@dimen/dimen_3_dip"
        android:color="@color/yellow" />
    <!--width 圆环实体部分的直径 设置不当会导致圆的左侧缺失 如图-->

    <size
        android:width="@dimen/dimen_20_dip"
        android:height="@dimen/dimen_20_dip" />
    <!--size 圆环的大小-->
</shape>
使用
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/dimen_10_dip"
    android:layout_marginRight="@dimen/dimen_15_dip"
    android:src="@drawable/hollow_circle" />

圆角

https://www.jianshu.com/p/c1d55c92e36c

四个角均为圆角 目录结构D:\androidWorks\MyApplication3\app\src\main\res\drawable\fillet.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    android:shape="rectangle">
    <!-- rectangle表示为矩形 -->

    <!-- 填充的颜色 -->
    <solid android:color="@color/colorBule" />

    <!-- 边框的颜色和粗细 -->
    <stroke
        android:width="1dp"
        android:color="@color/colorBule" />

    <!-- android:radius 圆角的半径 -->
    <corners android:radius="50dp" />

</shape>

只要顶部两个角为圆角的矩形 目录结构D:\androidWorks\MyApplication3\app\src\main\res\drawable\fillet.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!-- rectangle表示为矩形 -->

    <!-- 填充的颜色 -->
    <solid android:color="@color/colorBule" />

    <!-- 边框的颜色和粗细 -->
    <stroke
        android:width="1dp"
        android:color="@color/colorBule" />

    <!-- android:radius 圆角的半径 -->
    <corners
        android:bottomLeftRadius="0dp"
        android:bottomRightRadius="0dp"
        android:radius="2dp"
        android:topLeftRadius="50dp"
        android:topRightRadius="50dp" />

</shape>

发表评论

zh_CNChinese
zh_CNChinese