Resize images in bitmap in xml

I am new to Android programming. Recently, I had started on a project and would like to make a splash screen for the Android app. I had read and successfully implemented the splash screen after following this tutorial. However, I realise that my app logo stretches out of my screen, like this:

The following is my background_splash.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="">
        android:drawable="@drawable/splash_background" />

            android:src="@drawable/tap" />

I have tried


in <bitmap> but it does not work. Thus, I would like to know if there is a way to resize the image (without Java code, preferably) except for using an ImageView. Any help would be appreciated!


Just change




I faced the ditto same problem while designing splash screen for my app (followed the same link that you mentioned above and a few others) , and a bit of googling got me my answer.

The solution is simple and does not involve coding. ie. you do not need to specify height and width in your xml. As for why this is happening, your image resolution is higher than as specified below.


You need to provide image of various resolutions that map to various screen sizes. Following is a list of minimum screen size for various displays as provided by Google (all in pixels) :-

For Android Mobile Devices

LDPI- 426 x 320

MDPI- 470 x 320

HDPI- 640 x 480

XHDPI- 960 x 720

For Android Tablet Devices

LDPI- 200 x 320

MDPI- 320 x 480

HDPI- 480 x 800

XHDPI- 720 x 1280

So all you need to do is resize your image for all sizes, load the images in Drawable according to their sizes (Ex: drawable-hdpi contains the hdpi image) and pass it to the background_splash.xml (you can keep the same name ofcourse). Rebuild the project and run it. Should be as per your specification.

Note: Code does not need to be changed at all. For image resizing, you can use Adobe Photoshop (I find it easier to work with).

According to preference, you may also use 9 Patch image so that the image's border can stretch to fit the size of the screen without affecting the static area of the image.

Bitmap does not allow resizing of image dimensions using gravity = "center" and take a separate icon with specific size for splash screen.

Try this dont use drawable

if you want change background color that give it to Relative layout, if you want full image set to your scree (best for splash screen) that use match_parent to image view


        android:src="@drawable/splash" />


R you using ImageView try it I think it helps you...

ImageView img=(ImageView)findViewById(;
Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.sc01);
int width=200;
int height=200;
Bitmap resizedbitmap=Bitmap.createScaledBitmap(bmp, width, height, true);

Or check it

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android=""
    android:drawable="@drawable/splash_background" />

        android:src="@drawable/tap" />

If you want to resize the bitmap in an item, you should not use bitmap To change the dimensions use directly item .. example:

<layer-list xmlns:android="">

Bitmap does not allow resizing of image dimensions using gravity = "center"

Need Your Help

How to position a fixed div under another fixed div?

html css css-position

I am trying to set a fixed div div(menu) directly under another fixed div (header) and the positioning should also work with different screen sizes.

Issues regarding SVN folders and good repository name

svn repository-design svn-repository

I am a little bit confused how SVN related settings should be configured assuming I want to use SVN on my local machine. They are as below: