Dotted line XML in Android

Usman Khan picture Usman Khan · Apr 25, 2015 · Viewed 9.7k times · Source

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>

Answer

Giru Bhai picture Giru Bhai · Apr 25, 2015

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"