Drawing two strokes for Android ListView divider?

SyBer picture SyBer · Jan 27, 2013 · Viewed 8.2k times · Source

Is it possible to draw two strokes (one after another) for ListView divider?

I've tried the following drawable, but it only shows the first stroke:

<?xml version="1.0" encoding="utf-8"?>

<shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="line">
    <stroke
            android:color="#eeeeee"
            />
    <size
            android:height="1px"
            />

    <stroke
            android:color="#c1c1c1"
            />
    <size
            android:height="1px"
            />
</shape>

Answer

Tomik picture Tomik · Jan 27, 2013

Yes, it is possible. If you want to create it with shape drawables, you have to do it differently. A shape drawable can contain just one shape, one line in your case. You can combine two shapes in layer list drawable. Drawable in the layer list are drawn one above another, the last one at the top. To create two lines you just have to set the proper padding for each of the lines, so that both the lines are visible. The resulting drawable will be something like this (I made the lines thicker in the example):

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:bottom="2dp">
        <shape android:shape="line">
            <stroke
                    android:color="#eeeeee"
                    android:width="2dp"
                    />
            <size
                    android:height="4dp"
                    />
        </shape>
    </item>
    <item android:top="2dp">
        <shape android:shape="line">
            <stroke
                    android:color="#c1c1c1"
                    android:width="2dp"
                    />
            <size
                    android:height="4dp"
                    />
        </shape>
    </item>
</layer-list>