wbk727
wbk727

Reputation: 8408

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

Upvotes: 0

Views: 1774

Answers (2)

santosh kumar
santosh kumar

Reputation: 2962

You could try this:

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

Upvotes: 2

Ruslan altukhov
Ruslan altukhov

Reputation: 102

Good practice is not configuring size of XML drawables directly in file. You should set the size for the view in your layout file. For example if you have some button in your code and drawable shape.xml, your code could look like this:

<Button 
 .....
  android:drawable="@drawable/shape" >
<Button> 

But if you still wan't to set sizes you can use this code:

<size android:width="60dp"
    android:height="40dp" />

Upvotes: 0

Related Questions