Reputation: 4639
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:
But I need something like this:
How to fix it?
Upvotes: 6
Views: 4229
Reputation: 362
Add this drawable: dash_line.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="1dp"
android:color="#ff0000"
android:dashWidth="2dp"
android:dashGap="4dp" />
</shape>
Then use drawable as background:
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginBottom="10dp"
android:background="@drawable/dash_line"
android:layerType="software" />
Don't forget the attribute for low sdk devices
android:layerType="software"
Detail here: https://developer.android.com/guide/topics/graphics/hardware-accel
Upvotes: 0
Reputation: 2972
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"
Upvotes: 8