Search code examples
androidxmlandroid-drawablexml-drawable

How to set width of layer-list as a whole?


How can I specify the width of an XML drawable when using a layer-list? I want the width of the drawable (as a whole) to be set to 20dp but I don't where/how to set this + the preview pane doesn't help that much either.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <solid android:color="@color/blue" />
        </shape>
    </item>
    <item android:left="8dp" android:right="8dp">
        <shape>
            <solid android:color="#fff" />
        </shape>
    </item>
</layer-list>

enter image description here


Solution

  • You could try this:

        <shape>
            <solid android:color="#fff"/>
            <size android:height="10dp" android:width="20dp"/>
        </shape>