虚线本来用shape很好画,但是有时候画的时候虚线就是不显示,注意一下几点就行。
创建一个 shape 名为 bg_dash.xml
<shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="line"><!-- 显示一条虚线,破折线的宽度为dashWith, 破折线之间的空隙的宽度为dashGap,当dashGap=0dp时,为实线 -->
<stroke
android:width="0.5dp"android:color=#bbbbbb"
android:dashWidth="4dp"android:dashGap="1dp"/>
<!-- 虚线的高度 -->
<sizeandroid:height="1dp"/>
</shape>
1、只要注意 <stroke>里面with的值 比 <size> 里面的height 值小就行,否则不显示
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layerType="software"
android:background="@drawable/bg_dash"
android:id="@+id/vv"></View>
android:layout_width="match_parent"
android:layout_height="1dp"
android:layerType="software"
android:background="@drawable/bg_dash"
android:id="@+id/vv"></View>
2、View在使用的时候 需要添加android:layerType="software" 这一句