效果图:
代码:
1.横虚线
<?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:dashGap="3dp"
android:dashWidth="8dp"
android:width="1dp"
android:color="@color/btn_blue" />
<!-- 虚线的高度 -->
<size android:height="1dp" />
</shape>
2.竖直虚线
这里是先写横虚线,然后再通过旋转获得竖直虚线:
横虚线:
<?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:dashGap="10dp"
android:dashWidth="15dp"
android:width="1dp"
android:color="#DCDCDC" />
<!-- 虚线的高度 -->
<size android:height="1dp" />
</shape>
竖直虚线:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="-600dp"
android:right="-600dp">
<rotate android:drawable="@drawable/gray_imaginary_line_h"
android:visible="true"
android:fromDegrees="90"/>
</item>
</layer-list>
源码+使用资源下载:
https://download.csdn.net/download/yonghuming_jesse/10678013
最后推荐给一些想进大厂或者还没有拿到心仪offer的攻城狮们一本书,由大厂java面试官胡书敏编写,满满的干货,助你进到想去的公司。