最近开发用到一个虚线分割的分割线,在此做个笔记,首先来看看图吧
其实用到的就是一个drawable资源文件,下面就开始定义这个drawable文件:dotted_line_bg.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:dashGap="5dp"
android:dashWidth="5dp"/>
</shape>
在布局文件中使用
<View
android:layout_width="match_parent"
android:layout_height="@dimen/dp_2"
android:background="@drawable/dotted_line_bg"
android:layerType="software" />
注意 android:layerType=“software” 运行就可以看到虚线的效果了