9

all.

I want to make splashscreen:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

drawable/background_splash:

<?xml version="1.0" encoding="utf-8"?>

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

<item android:bottom="16dp">
    <bitmap
        android:gravity="center|fill_horizontal"
        android:src="@drawable/splash_logo"
        />
</item>

<item android:bottom="16dp">
    <bitmap
        android:gravity="bottom"
        android:src="@drawable/logo"/>
</item>

But I have no ability to make bitmap with android:src="@drawable/splash_logo" resize as centerCrop scale in ImageView( I need my bitmap fill all width) For now it's size as size in resource in pixels. If i make it much larger it will be larger the screen. I tried scale drawable and no sense.

Do you have any suggestions?

Yurii Kot
  • 316
  • 3
  • 11

2 Answers2

1

I was able to achieve filling screen, but keep in mind, it will be a bit stretched on 18:9 screens

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/splash_2_x2"
        android:top="0dp"
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"/>
</layer-list>
Dmytro Rostopira
  • 10,588
  • 4
  • 64
  • 86
  • For filling the screen you just need the gravity property like `android:gravity="fill"`, but this will not achieve centerCrop as the question in this post. – luis Jun 03 '21 at 15:50
0

Change this Line to

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>

To

 <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:background">@drawable/background_splash</item>
</style>

because android:windowsBackground attribute will not be able to show splash at full screen. It's good way u use android:background for splash. Then if you want you can call centercrop in your Splash Activity. Hope this helped!!

Queendevelopers
  • 183
  • 3
  • 20
  • Thanks, but It have the same result – Yurii Kot Aug 22 '16 at 15:05
  • Does your splash Image displaying in the full screen? – Queendevelopers Aug 22 '16 at 15:14
  • No, now it has 60-70% of the width. I think at different screeen sizes it has different result. 60-90% – Yurii Kot Aug 22 '16 at 15:19
  • Crop image at 3 different size ldpi, mdpi and hdpi and put those images in mipmap and call them from mipmap like @mipmap/logo and @mipmap/splash_logo. This is the only way to fit images in all size of Android Phone and tablet see https://developer.android.com/training/basics/supporting-devices/screens.html – Queendevelopers Aug 22 '16 at 15:24
  • One more solution you may find helpful is you can define centerCrop in styles.xml just give it a try, define this in your styles.xml – Queendevelopers Aug 22 '16 at 15:28
  • 3
    `android:background` is a view attribute, not a theme attribute. Never use it in your themes. – tasomaniac Feb 08 '17 at 09:46