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.
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" />
You can use following code . it may help you. Create a dotted.xml in drawable folder like this...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:color="#A52A2A"
android:dashWidth="10px"
android:dashGap="10px" />
</shape>
then use this xml in your layout with image view like this....
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is above line of code " />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:src="@drawable/dottede" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="this is below code " />
</LinearLayout>