Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize drawable in layer-list item

I have this:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">

            <solid android:color="#000000"/>
            <size android:width="70dp" android:height="70dp"/>
        </shape>
    </item>

    <item android:drawable="@drawable/ic_person_white_48dp"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:layout_width="10dp"
        android:layout_height="10dp"
        />
</layer-list>

How can I resize the drawable image? Currently, it's too big for the shape.

like image 857
user5188154 Avatar asked Aug 05 '15 05:08

user5188154


2 Answers

I would suggest using A ScaleDrawable. It essentially changes the size of the child drawable using

android:scaleHeight="50%"
android:scaleWidth="50%"

Both are expressed as a percentage of the drawable's current bound.

like image 88
frgnvola Avatar answered Nov 15 '22 19:11

frgnvola


Maybe it's and old question, but this is how I resize a drawable in a layer-list

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <layer-list>
            <item>
                <shape android:shape="oval">
                    <solid android:color="#000000"/>
                    <size android:width="10dp" android:height="10dp"/>
                    <padding android:bottom="30dp" android:top="30dp"
                             android:left="30dp" android:right="30dp"/>
                </shape>
            </item>
            <item>
                <bitmap android:src="@drawable/ic_person_white_48dp"/>
            </item>
        </layer-list>
    </item>
</selector>

No need for android:height or android:width

like image 28
adonozo Avatar answered Nov 15 '22 19:11

adonozo