in my layout I am trying to draw a DOTTED LINE.for drawing a horizontal line i am defining a view in my layout file.
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="@drawable/customdots" />
and 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>
But i don't get any line using this code. please help me out.
When i use customdots.xml in the listView Divider as
android:divider="@drawable/customdots"
it shows a good dotted line
I was pulling my hair on this issue too until I figured out there is a bug in the latest versions of Android when rendering lines like this.
This bug can be circumvented by adding android:layerType="software" to the view which is using the dotted line as a background.
Example:
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With