Removing padding from layerlist item

229 Views Asked by At

I am trying to add a bitmap as a Splash Screen. I have created a separate Splash Theme and added android:windowBackground to a Layer list drawable containing that bitmap.

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

Following is the code for my layer list drawable(@drawable/splash_bg):

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

Currently the drawable looks like this:

splash sample

I want to remove the extra padding around the image, without streching the image. Some thing like Center Crop in ImageView.

If the center crop is not possible, then i would like to make it fit horizontally(without stretching), and show a solid background at the top and bottom.

So far I have tried all the attributes of gravity, and tried using the inset tag, but all of them seem to be stretching the image.

1

There are 1 best solutions below

2
snachmsm On

windowBackground isn't best way to set up such image (splash), it probably should be used only with color (if with bitmap then with tileMode="repeat" in some cases). there is no reliable way to set up different bitmaps for different screen resolutions/ratios. it would be the best to set ImageView with proper scaleType, CENTER_CROP seems to be the best option