我基本上将以下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
大于屏幕,则超出屏幕。
我看到了 3 种解决方法,但都有缺点:
- 设置
left
/right
in<item
,但这需要 API 23+ - 因等而异
@drawable/logo
,但我使用的是密度拆分,这会在将 apk 重用于其他设备(apk 站点、“移动到新设备”-传输 apk 的应用程序等)时破坏它xhdpi
xxhdpi
- 使用带有 的布局
ImageView
,但这有明显的延迟
如何正确/没有缺点地做到这一点?