Splash Screen in Android is stretched

Viewed 120

I added a splash screen that will be displayed, but it is always stretched to the edge. I want to clip it if the screen doesn't fit.

Launch Screen Xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item>
        <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
            android:gravity="fill|clip_horizontal"
            android:src="@drawable/splash_screen"/>
    </item>
</layer-list>

styles.xml

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
    </style>

    <style name="SplashTheme" parent="AppTheme">
        <item name="android:windowBackground">@drawable/launch_screen</item>
    </style>

</resources>

I tried many combinations of android:gravity, but I didn't find the right one. Also, all combinations I found in the internet didn't work for me. I am testing on a Google Pixel 3a which has a resolution that doesn't fit exact to any of the drawable splash images.

Is it possible to clip the image?

1 Answers

I didn't find a solution how to crop it, but I took the just image without background, add the background with xml and center it like this:

<?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="161dp"
        android:height="70dp"
        android:drawable="@drawable/my_image"
        android:gravity="center" />

</layer-list>
Related