我想使用shape
制作虚线。
这是我的XML:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="line">
<stroke android:color="@color/grey_divider"
android:width="1dip"
android:dashWidth="5dip"
android:dashGap="13dip"/>
</shape>
</item>
</selector>
如何解决?
答案 0 :(得分:4)
试试这个
在drawable中创建一个xml文件。(例如dashed_line.xml)
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:color="#C7B299"
android:dashWidth="10px"
android:dashGap="10px"
android:width="1dp"/>
</shape>
现在在你的布局中使用这个xml文件。
android:background="@drawable/dashed_line"
答案 1 :(得分:0)
添加此可绘制对象:dash_line.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="#ff0000"
android:dashWidth="2dp"
android:dashGap="4dp" />
</shape>
然后使用drawable作为背景:
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginBottom="10dp"
android:background="@drawable/dash_line"
android:layerType="software" />
不要忘记sdk设备低的属性
android:layerType="software"
详细信息在这里:https://developer.android.com/guide/topics/graphics/hardware-accel