Android 使活动布局看起来与可绘制的启动画面相同

Zhe*_*Liu 5 android android-layout

我正在通过更改启动画面

<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>
Run Code Online (Sandbox Code Playgroud)

主题的属性。

这个 drawable/background_splash 看起来像这样

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
    <item android:drawable="@color/colorPrimary"/>
    <item>
        <bitmap
            android:src="@drawable/ic_logo_black"
            android:gravity="center"/>
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

对于我的启动器活动,它会在后面进行一些计算,然后有条件地导航到其他活动。此计算需要服务器,因此它会在此活动上停留一段时间。

为了让体验更好,我希望这个活动看起来和启动画面一样。

所以我基本上是为了布局而这样做的。

<?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="@drawable/background_splash"
    android:orientation="vertical">

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

但是,有了这个设置。我可以注意到,一旦从启动画面转到启动器活动,徽标就会向上移动大约 5-10 像素。

我的问题是,我该怎么做才能使这种转变完全消失?我显然可以硬编码一些边距。但我不确定这是否适用于所有设备尺寸。

那 5-10px 的偏移到底是什么?我基本上使用确切的图像作为布局中的背景。

我注意到如果我没有为我的 splashActivity 布局设置任何背景,这个问题就解决了。但我仍然想要一个背景,因为在我的用户工作流程中,用户可能会被重定向到这个屏幕。我不希望他们看到一个空的空白屏幕 =/

Zhe*_*Liu 0

我不知何故没有为我的 SplashActivity 设置任何背景图像。

然后它是透明的并看到初始窗口背景。