Dotted / Dashed Line

1

I'm trying to create a split line in my App as shown below.

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:color="#C7B299"
       android:dashWidth="10px"
       android:dashGap="10px"
       android:width="1dp"/>
</shape>

view.xml :

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

But it's not working properly, instead of getting a dotted line it's getting a straight line.

Could anyone tell me the reason?

    
asked by anonymous 11.05.2017 / 13:22

1 answer

2

What might be causing this is the use of the px unit for the dimensions of android:dashWidth and android:dashGap .

On devices with high pixel density screen it is possible that 10 pixels are not perceptible as a space, giving the idea that the line is continuous.

In order for the dimensions to be independent of the density of the screen they should be indicated using the dp unit.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">

    <stroke
       android:color="#C7B299"
       android:dashWidth="10dp"
       android:dashGap="10dp"
       android:width="1dp"/>
</shape>
    
11.05.2017 / 16:08