画一条虚线作为分割线
1.先写一个shape,命名为shape_line_dash.xml
虚线
?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="1dp"
android:color="#f3f3f3"
android:dashWidth="3dp"
android:dashGap="3dp" />
</shape>
虚线框
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#f3f3f3"
android:dashWidth="3dp"
android:dashGap="3dp" />
</shape>
虚线圆
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="1dp"
android:color="#f3f3f3"
android:dashWidth="3dp"
android:dashGap="3dp" />
</shape>
顶部虚线
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="-2dp"
android:right="-2dp"
android:bottom="-2dp">
<shape>
<stroke
android:width="1dp"
android:color="#f3f3f3"
android:dashWidth="3dp"
android:dashGap="3dp" />
</shape>
</item>
</layer-list>
底部虚线
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape>
<stroke
android:width="1dp"
android:color="#f3f3f3"
android:dashWidth="3dp"
android:dashGap="3dp" />
</shape>
</item>
</layer-list>
2.使用
<View
android:layerType="software"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:background="@drawable/shape_line_dash"/>
注意:
1.引用的时候,View的height要大于shape中stroke的width,不然会显示不出来,或者显示不全。
2.还要设置一个属性layerType为software,不然显示出来的是实线。
总结来源:https://blog.csdn.net/devilnov/article/details/76177813