在我的布局中,我正在尝试绘制一个DottED LINE.for绘制一条水平线,我在我的布局文件中定义了一个视图.
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="@drawable/customdots" />
和customdots.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:left="10dp"
android:right="10dp"
android:width="4dp"
android:drawable="@drawable/dotted" />
</layer-list>
dotted.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<size
android:height="4dp"
android:width="1024dp"/>
<stroke
android:width="4dp"
android:dashWidth="4dp"
android:color="@android:color/black"
android:dashGap="5dp"/>
</shape>
但是我没有使用这段代码.请帮帮我.
当我在listView Divider中使用customdots.xml时
android:divider="@drawable/customdots"
它显示了一个很好的虚线
解决方法
我也在解决这个问题,直到我发现最新版本的Android在渲染这样的线条时出现了一个错误.
通过将android:layerType =“software”添加到使用虚线作为背景的视图中,可以避免此错误.
例:
dotted.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:dashGap="3dp"
android:dashWidth="8dp"
android:height="2px"
android:color="#FFFFFF" />
</shape>
layout.xml:
<View
android:id="@+id/vDottedLine"
android:background="@drawable/dotted"
android:layout_width="match_parent"
android:layout_height="2px"
android:layerType="software" />