我正在为使用 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:scaleType
和 android:tileMode
没有成功。即使我将 Logo 移动到 <bitmap>
项目中的标签仍然是一样的。我确实发现,当我将重力 Prop 更改为某个不同的值时,扭曲的 Logo 会相应地移动。但我无法摆脱它。我也不明白,如果只定义一次,为什么 Logo 会显示两次。
感谢任何帮助。谢谢。
最佳答案
您可以在 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/