Shape虚线
1、在Drawable上面写Shape的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="@color/bg_shop"
android:dashGap="5dp" //虚线间隔
android:dashWidth="5dp" /> //虚线宽度
<!-- 虚线的高度 -->
<size android:height="0.2dp" />
</shape>
2、在布局XML设置shape
<View
android:layout_width="match_parent"
android:layout_height="1.5dp"
android:layout_below="@+id/view_head"
android:layout_marginLeft="@dimen/dp_22"
android:layout_marginRight="@dimen/dp_22"
android:layout_marginTop="123.8dp"
android:background="@drawable/line_dotted"
android:layerType="software"/>
3、效果图
PS:dashGap //虚线间隔,dashWidth //虚线宽度
必须得加上android:layerType=”software”,否则不生效,成直线。