开发中遇到需要画虚线,挺简单的。
1.在drawable创建shape_dash_line
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<size android:height="1dp" />
<stroke
android:dashGap="4dp"
android:dashWidth="8dp"
android:width="1dp"
android:color="#ffeaebf0" />
</shape>
然后在自己想用的地方改就可以了
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="center_vertical"
android:layerType="software"
android:background="@drawable/shape_dash_line" />