Android使用shape设置分割线不显示问题(踩坑)
需要设置虚线状分割线,首先将虚线样式用shape写出,然后设置View的android:background="@drawable/dottet_shape"来实现。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:color="#F4F4F4"
android:width="0.8dp"
android:dashGap="2dp"
android:dashWidth="2dp"></stroke>
<size android:width="1000dp"/>
</shape>
其中color为虚线格式、width为虚线高度,dashGap为间隔长度、dashWidth为虚线每一格的长度。
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@drawable/dottet_shape"/>
需要注意View与view不同,使用小写会报错。另外View的android:layout_height="1dp"必须大于shape的android:width=“0.8dp”。假如两者大小相等虚线显示不出来(这是一个坑标记一下)。