Resize images in bitmap in xml

Viewed 24936

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:

Stretched out app logo

The following is my background_splash.xml:

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

    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/tap" />
    </item>
</layer-list>

I have tried

android:width="75sp"
android:height="75sp"

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!

8 Answers

Try to use item instead of bitmap.

Bitmap has no option to change its size.

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

    <item android:drawable="@android:color/white"/> 

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

</layer-list>

There's more simple way to do it. In your launch_background.xml file, remove that bitmap tag and just add it like this

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