Android L is not able to draw dotted line as drawa

2019-06-22 04:56发布

问题:

Android L is not able to draw dotted line as drawable background as below:

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

    <stroke
        android:dashGap="1dp"
        android:dashWidth="1dp"
        android:color="#999999" />

    <size android:height="1dp" />

    </shape>
</item>
</selector>

I am also using layerType='software' in xml. Kindly help.

回答1:

1.The view must be at least 2dp in height (or wrap_content), in order for it to display since a stroke is designed to go around the view and it doesn't have room to do so in 1dp.

2.Add width to your xml:

<stroke
    android:width="1dp"
    android:dashGap="1dp"
    android:dashWidth="1dp"
    android:color="#999999" />

<size android:height="1dp" 
    android:width="1dp"/>

3.Use layerType='software'