问题
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?
回答1:
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!!
回答2:
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>
来源:https://stackoverflow.com/questions/39082029/make-drawable-do-centercrop-in-layer-list