Erma Isabel Erma Isabel - 1 month ago 28
Android Question

Android bitmap image size in xml

In my xml file, i am using bitmap as the following

<bitmap
android:src="@drawable/Icon"
android:gravity="center"/>


Here the image width of the icon exceeds the screen.

I tried android:width="100dp" and all. But it isn't working.

Whole xml file:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<stroke android:width="3dp" android:color="@color/black" />
<solid android:color="@color/bg_green" />
</shape>
</item>
<item>
<bitmap
android:src="@drawable/Icon"
android:gravity="center"/>
</item>
</layer-list>


How can i reduce the width and height of the above bitmap?

Please help,
Thanks

Answer

Try to use ImageView instead :

<ImageView
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:scaleType="center"
    android:src="@drawable/Icon" />

UPDATE :

From Android Developers I saw that there is no tag for Bitmap XML that allow you to change it size. You need to do this via some Graphic Applications