1.res/drawable下的xml文件
dotted_line.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<!--线宽为dashWith,线之间空隙dashGap,dashGap=0dp时,是实线 -->
<stroke
android:width="1dip"
android:color="#000000"
android:dashWidth="2dp"
android:dashGap="2dp">
</stroke>
<!-- 虚线高度 -->
<size android:height="1dip" />
</shape>
参考博客:1.Android 虚线分割Shape【传送门】
2.布局xml中使用
方式一:view的方式
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@drawable/dotted_line"/>
方式二:LinearLayout的方式
<LinearLayout
android:layout_width="match_parent"
android:layout_height="2dip"
android:layout_marginLeft="8dp"
android:background="@drawable/bg_line_dotted"
android:layerType="software"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fl_ip_address" />
3.参考博客:
1.Android分割线divider(内含Android虚线分割线失效成实线解决方案)【传送门】
4.虚线失效问题:3的参考博客