天天看点

Android使用Shape绘制虚线

虚线shape.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="#EAEAEA"
        android:dashWidth="5dp"
        android:dashGap="5dp" />
</shape>
           

虚线使用

<View
	android:layout_width="match_parent"
	android:layout_height="2dp"
	android:background="@drawable/line_dash_1"
	android:layerType="software" />
           
注意,使用时View一定要配置android:layerType=“software”, 否则会显示为实线