如何在启动画面后制作相同的布局

Ale*_*nin 5 android android-layout

我的启动画面是一个layer-list可绘制的应用程序主题背景。就这个:

background_splash.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@color/dark_blue"/>

    <item android:top="100dp">
        <bitmap
            android:gravity="top"
            android:src="@mipmap/img_logo"/>
    </item>

</layer-list>
Run Code Online (Sandbox Code Playgroud)

如您所见,我将徽标放置100dp在顶部留有边距。然后我尝试在我的片段布局中做同样的事情:

fragment_start.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@mipmap/bg_create_account">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/img_logo"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="100dp" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

但是布局中的徽标比启动屏幕上的徽标低。我想,问题出在Activity. 但如果我设置:

<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>
Run Code Online (Sandbox Code Playgroud)

什么都没有发生。我总是看到徽标从上到下的“跳跃”大约 10-20 dp。我怎样才能避免它?

编辑:我的活动xml:

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

    <LinearLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

编辑 2:我尝试手动获取距离,如果我设置<item android:top="125dp">(或 126dp)并离开,android:layout_marginTop="100dp"我看不到“跳跃”。这意味着差异是 25 或 26 dp,但它们在哪里?

编辑 3:根据 Bryan 的回答,该问题仅存在于 Android 4.4(API 19) 及更高版本中。为了避免它,我styles.xml在文件夹中覆盖values-19了:

<item name="android:windowTranslucentStatus">true</item>
Run Code Online (Sandbox Code Playgroud)

Bry*_*yan 2

您用于启动屏幕的可绘制似乎没有考虑状态栏的大小,但Activity确实如此。这是您观察到的约 25dp 的差异,但约 25dp 的高度不能保证在所有设备上都相同。