androidandroid-shape

Shape dashed line, dash doesn't work


I want to make dashed line using shape.

This is my 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>

On my device I see this: enter image description here But I need something like this:

enter image description here

How to fix it?


Solution

  • Try this

    Make one xml file in drawable.(e.g. 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>
    

    And now use this xml file in your layout.

    android:background="@drawable/dashed_line"