Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 709
vinb Avatar asked Jul 02 '14 16:07

vinb


People also ask

How do I make a dotted dashed line in android?

This example demonstrates how do I make a dotted/dashed line in Android. Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 - Add the following code to res/layout/activity_main. xml.

How do you make a dash line on android?

Go to res > drawable > new > drawable resource file and create a new file and name it “dashed_underline. xml” and define all properties of the dashed line that we need.

What is r drawable?

R. drawable. image means the drawable resource, in this case image. Drawable means graphic which can be drawn. Every drawable is stored in res/drawable folder.

What is stroke in shape android?

Sometimes you want an outline around your shape and to do that you can use the stroke tag. You can specify the width and color of the outline using android:width and android:color.


1 Answers

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'

like image 57
Itai Hanski Avatar answered Oct 28 '22 05:10

Itai Hanski