Android bitmap image size in XML

Erma Isabel picture Erma Isabel · Apr 15, 2014 · Viewed 94.3k times · Source

In my XML file, I'm 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.

Complete 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?

Answer

MaxF picture MaxF · Nov 13, 2017

Just use

<item
    android:width="200dp"
    android:height="200dp"
    android:drawable="@drawable/splash_background"
    android:gravity="center" />

instead

<item
    android:left="200dp"
    android:right="200dp">

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

</item>