我的闪屏有两个布局,它们基本上由一个位于屏幕中心的图标组成。
其中之一就是drawable/launch_screen.xml
。这一条用于AppTheme
。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<item android:drawable="@android:color/black" />
<item>
<bitmap
android:gravity="center"
android:src="@android:drawable/ic_menu_camera" />
</item>
</layer-list>
我将此文件用于我的应用程序主题,如下所示:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/launch_screen</item>
</style>
另一个是layout/launch_screen.xml
。这由库react-native-splash-screen
使用。
<?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="@android:color/black"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_camera" />
</LinearLayout>
如果你想知道细节,我遵循this guide构建了闪屏机制。一旦应用程序打开,AppTheme
就会显示drawable/launch_screen
作为背景,然后闪屏就会出现,layout/launch_screen
也会显示出来。
因此,这些文件基本上是一个以空白屏幕为中心的图标,没有任何其他样式。我希望他们都能完美地居中。然而,在现实中,它们看起来像:
第一张图片是drawable
格式的,第二张是layout
格式的。如你所见,第二个是用LinearLayout
构建的,它的位置有点靠上。由于这些屏幕是一个接一个地显示,所以感觉像是图标向上移动。
我曾尝试在ImageView中添加边距或填充,但在不同的设备上不能呈现相同的效果。此外,我还尝试使用具有不同参数和组合的gravity
和layout_gravity
,但它们的居中位置都不完全相同。我在想,状态栏可能会导致这个问题,但状态栏总是存在的,应用程序总是全屏的。你知道为什么会出现这个居中问题吗?提前谢谢。
发布于 2020-01-14 03:54:58
我认为这是因为活动背景忽略了底部导航偏移。看起来这种行为没有问题
https://stackoverflow.com/questions/59718223
复制相似问题