android - PNG Logo 在 Android 5 (api v22) 的启动画面中显示两次并变形

标签 android react-native android-layout splash-screen

我正在为使用 native react 的 Android 应用程序构建启动画面。启动画面由纯色背景和 PNG 格式的 Logo 组成。 Splashscreen 在新的 android 版本上运行良好,但在 android 5(api 版本 22)上 Logo 显示两次,一次正确,一次扭曲(在整个屏幕上拉伸(stretch))。截图见文末。

启动画面是使用 npm 包设置的 react-native-splash-screen它的源代码如下所示:

res/layout/launch_screen.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splashscreen"
    android:orientation="vertical">
</LinearLayout>

drawable/splashscreen 看起来像这样:

res/drawable/splashscreen.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@color/purple"/>
    <item
        android:width="257dp"
        android:height="33dp"
        android:drawable="@mipmap/logo"
        android:gravity="center" />
</layer-list>

我尝试了几乎所有不同的 android:gravity 组合, android:scaleTypeandroid:tileMode没有成功。即使我将 Logo 移动到 <bitmap>项目中的标签仍然是一样的。我确实发现,当我将重力 Prop 更改为某个不同的值时,扭曲的 Logo 会相应地移动。但我无法摆脱它。我也不明白,如果只定义一次,为什么 Logo 会显示两次。

感谢任何帮助。谢谢。

bad splashscreen

最佳答案

您可以在 LinearLayout 中放置一个 ImageView,然后将 LinearLayout 背景设置为 @color/purple并将ImageView背景改为@mipmap/logo,如下图:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/purple">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@mipmap/logo"
        />

</LinearLayout>

关于android - PNG Logo 在 Android 5 (api v22) 的启动画面中显示两次并变形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56566495/

相关文章:

javascript - 如何隐藏特定屏幕上的底部标签栏(react-navigation 3.x)

react-native - 为 Android 和 iOS 开发组件的正确方法是什么?

java - 无法弄清楚如何显示 Android 对话框

android - switch 语句后无法访问的代码

java - 用于发送消息而不是短信的 Intent 选择器

android - Android SDK版本升级

android - 当设备处于 sleep 状态时对敲击电话执行操作?

react-native - 违反不变性的react-native-webview

android - 如何以编程方式(在运行时)滑动一行 RecyclerView?

android - 如何让我的项目在多个屏幕上运行?