我基本上使用以下xml为Android 启动画面: 使用windowBackground
的空活动:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
background_splash.xml
:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/defaultBackground" />
</item>
<item>
<bitmap
android:src="@drawable/logo"
android:tileMode="disabled"
android:gravity="center"/>
</item>
</layer-list>
只要
logo.png
小于屏幕大小,它就可以很好地工作。但如果logo.png
大于屏幕大小,则会超出屏幕范围。
我看到了三个解决方法,但都有缺点:
- 在
<item
中设置left
/right
,但这需要 API23+。 - 为
xhdpi
、xxhdpi
等不同密度设置不同的@drawable/logo
,但我正在使用Density Split,这将在重用 apk 的其他设备时破坏它(apk 网站,“移动到新设备” - 传输 apk 等应用)。 - 使用一个带有
ImageView
的布局,但这会有明显的延迟。