Android 7.1 上带有黑条的冷启动启动画面

Cold start splash screen with black bars on Android 7.1

我正在实施 Google 推荐的 "cold start" 启动画面

来源:

https://www.bignerdranch.com/blog/splash-screens-the-right-way/ https://plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhd https://material.io/guidelines/patterns/launch-screens.html

但是,在具有 pure Android 7.1 (Nexus 5X) 的设备上,启动画面背景未正确调整大小,产生黑条。

灰色方块只是为了隐藏徽标,因为应用程序尚未发布

这是我的background_splash.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:gravity="center"
        android:drawable="@drawable/background_img"/>
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/logo_img"/>
    </item>
</layer-list>

这是我的主题:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
    <item name="android:fitsSystemWindows">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>
<item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/logo_img"/>
    </item>

如果可能,在此代码中分配 scaleType。

通过在位图元素中添加属性 android:tileMode="clamp" 我能够解决问题。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <bitmap
            android:tileMode="clamp"
            android:gravity="center"
            android:src="@drawable/hartwall_arena_bg"/>
    </item>

    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/hartwall_arena_logo"/>
    </item>

</layer-list>

我对 "solution" 没有很好的解释,所以如果有人解释得更好,我会把它标记为正确的回答,而不是我的:)

在我的例子中,添加选项 android:tileMode="clamp" 解决了黑色边框的问题,但背景图像变形了,因为根据文档:https://developer.android.com/guide/topics/resources/drawable-resource

clamp 选项 Replicates the edge color if the shader draws outside of its original bounds 这样在纯色背景下看起来会更好。

在 'solve' 使用夹紧选项出现黑边问题但图像失真后,我知道问题出在图层列表中的 bitmap 项上。所以我添加如下位图并解决问题:D

<item>
    <bitmap
        android:gravity="fill_horizontal|fill_vertical"
        android:src="@drawable/background"/>
</item>