Search code examples
androidshapedrawable

Resize bitmap inside a drawable layer-list not having effect


I want to resize a bitmap in a layer-list, added as an item.

This is what I have tried,

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

        <solid android:color="@android:color/white" />

        <size
            android:width="46dp"
            android:height="46dp" />
    </shape>
</item>
<item
    android:width="11dp"
    android:height="24dp"
    android:gravity="center">
    <bitmap android:src="@drawable/facebook_f" />
</item>
</layer-list>

Using Android Studio 2.0 Preview 5, the preview shown is perfect but the actual image is a blunder.

Preview by AS,

enter image description here

Actual image,

enter image description here

Changing image resource size manually or in the xml itself does not change anything.

Note : 'f' shape image dimensions are 53 * 128.

EDIT : AS was using API version 23 to render layouts. When I changed it to 21 (on which I was testing it too), it appeared blurred. I checked the same on Android M device and the images were perfect. So now, this xml is behaving API specific.


Solution

  • The android:height and android:width for <item> are only available for API 23 and above. If you use these attributes for API below 23, it will not give you an error, but simply ignore it.