【问题标题】:Layout and drawable are not centered the same way布局和drawable的居中方式不同
【发布时间】:2020-04-30 06:15:45
【问题描述】:

我的初始屏幕有两种布局,基本上由一个位于屏幕中心的图标组成。

其中一个是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,但它们的中心要么不完全相同。我在想状态栏可能会导致这个问题,但状态栏总是在那里,应用程序总是全屏。你有什么想法为什么会出现这个居中问题?提前致谢。

【问题讨论】:

  • 您找到解决方案了吗?

标签: android react-native android-linearlayout splash-screen android-drawable


【解决方案1】:

我认为这是因为活动背景忽略了底部导航偏移。这种行为似乎没有问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-15
    • 1970-01-01
    • 1970-01-01
    • 2016-02-01
    • 1970-01-01
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多