第一步:先写一个资源dotted_line.xml,如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:dashWidth="2dp"
android:dashGap="2dp"
android:width="1dp"
android:color="@color/color_008089"/>
</shape>
第二步:在控件View中引用,如下:
<View
android:id="@+id/divider_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="@dimen/dp_15"
android:background="@drawable/dotted_line"
android:layerType="software"
app:layout_constraintTop_toBottomOf="@+id/item_icon"/>
写在最后:一定要注意,View中的android:layout_height一定要比Shape中的android:width大,不然会不显示;听说,View中也必须要加android:layerType="software",不然高版本会显示成一根线。