Search code examples
androidxmldotted-line

Plane line showing instead of Dotted line in xml android


I am trying to show dotted line "---" on my view. I have searched many examples on stackoverflow and using similar drawable code and calling on my view as well. On my IDE it is showing Dotted Line but when i am running it on my device it is showing plane straight line. Please suggest me in this regard why it is happening.

My Drawable 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="2dp"
        android:width="1dp"
        android:color="@color/black" />
</shape>

My View where i am calling it.

 <View
        android:layout_width="fill_parent"
        android:layout_height="10dp"
        android:background="@drawable/dotted_line"
        android:layout_marginTop="5dp"/>

Solution

  • If your View is not working then try to use ImageView it's working

     <ImageView
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:src="@drawable/dotted_line"
        android:layout_marginTop="5dp"
        android:layerType="software" />