1,创建shape 文件
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<!--<stroke-->
<!--android:width="4px" 虚线的高度-->
<!--android:color="@android:color/white"-->
<!--android:dashGap="5dp" 虚线之间的间隔-->
<!--android:dashWidth="10dp" 每个虚线的宽度/>-->
<stroke
android:width="4px"
android:color="@android:color/white"
android:dashGap="5dp"
android:dashWidth="10dp" />
</shape>
2,使用
<TextView
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@drawable/dash_line"
android:layerType="software"/>
4.0以上的设备需设置android:layerType=“software” ,不然会变成实线
3,效果
上面是单线条,如果需要实现虚线边框效果的话,把android:shape="line"删掉就好了,或者将line改成rectangle