0

In my Splash Screen, I have an image that spreads all over the screen and because of this, the image is not looking good - like it got stretched.

I wanted to fix this by adding "android:height" attribute to the Splash Screen style and change the image height but the image remains stretched.

Apparently, the android:height attribute is affecting all of the views that inside the layout that related to the Splash Screen

This is my style for the splash screen:

<style name="splashScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@mipmap/app_icon</item>
    <item name="android:height">100dp</item>
</style>

Any ideas on why android:height affect the layout views and not the Splash Screen image?


note:

I saw this question talking about different images for different screen sizes, but the difference is that I don't want the image to spread all over the screen.

RKRK
  • 1,284
  • 5
  • 14
  • 18
Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
  • the property you are looking for is android:layout_height not android:height try that property. – raj kavadia May 18 '19 at 08:22
  • @rajkavadia thank you but that did not worked – Tamir Abutbul May 18 '19 at 08:24
  • The Theme window background has no mechanism to set the image size or scale type. Your need can be implemented by https://developer.android.com/guide/topics/resources/drawable-resource#XmlBitmap. Using the center option may help you. – Tshunglee May 18 '19 at 08:33

1 Answers1

2

You using <item name="android:height">100dp</item> for root view of the Activity. Its not instance of View class, it smth else. And you cant set height for it, Activity should match available area.

To fix stretched image, try this. Set background not a bitmap, but the drawable

<style name="splashScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/shape_background_splash</item>
</style>

and create this drawable

<?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>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/app_icon"/>
    </item>
</layer-list>

if you have a bitmap for all scales it should looks good