2

I am working on an Android application in which I want to use dotted line XML as a divider in my layout. For this I have used different drawables for this but instead to make a dashed dotted line, it is making a line.

My drawable is given below:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">
    <stroke
        android:color="#FF404040"
        android:width="1dp"
        android:dashGap="3dp"
        android:dashWidth="1dp"
    />
    <size
        android:height="3dp"
    />
</shape>
halfer
  • 19,824
  • 17
  • 99
  • 186
Usman Khan
  • 3,739
  • 6
  • 41
  • 89
  • 1
    Possible duplicate of [How do I make a dotted/dashed line in Android?](https://stackoverflow.com/questions/6103713/how-do-i-make-a-dotted-dashed-line-in-android) – Vladimir Markeev Oct 24 '17 at 14:30

4 Answers4

12

Dashed lines are not supported in GL mode. So Add

android:layerType="software"

for e.g.

<ImageView
    android:layerType="software" // add here
 ...

in your xml layout for view or programmatically as

view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

Or Turn off hardware -acceleration like this:

android:hardwareAccelerated="false"
Giru Bhai
  • 14,370
  • 5
  • 46
  • 74
  • thanks for your reply. Can you please tell me where i can put layerType, can you please show it in my code snippet. Thanks – Usman Khan Apr 25 '15 at 09:42
2
use Below code

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="90"
    android:toDegrees="90" >

    <shape android:shape="line" >

        <stroke

            android:width="1dp"
            android:dashGap="6px"
            android:dashWidth="6px"
            android:color="#C7B299" />
    </shape>

</rotate>
Brinda Rathod
  • 2,693
  • 1
  • 20
  • 32
1

may be this help you..

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">

    <stroke
       android:color="#C7B299"
       android:dashWidth="10px"
       android:dashGap="10px" />
</shape>

just refer this .. How do I make a dotted/dashed line in Android?

Community
  • 1
  • 1
Moinkhan
  • 12,732
  • 5
  • 48
  • 65
1

Try this

<?xml version="1.0" encoding="utf-8"?>
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="line">
        <stroke
            android:color="#FF404040"
            android:width="5dp"
            android:dashGap="10dp"
            android:dashWidth="10dp"
            />

    </shape>
N J
  • 27,217
  • 13
  • 76
  • 96