3

I have a layout that transitions between 2 Scenes.

layout.xml

<FrameLayout
    android:id="@+id/framelayout_1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    // Some background views.

    <FrameLayout
        android:id="@+id/scene_root"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include layout="@layout/scene_a" />
    </FrameLayout>


</FrameLayout>

res/layouts/scene_a.xml

<android.support.constraint.ConstraintLayout
    android:id="@+id/constraintlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">

    // Child views removed for brevity
</android.support.constraint.ConstraintLayout>

Scene B layout is identical.

In the activity, ViewCompat.setOnApplyWindowInsetsListener(frameLayout, (v, insets) -> insets); is called to use fitsSystemWindows with FrameLayout.

The views are correct on initial view inflation i.e views are drawn under the status bar, but content is pushed down by the window insets to avoid the status bar.

However, when I transition to Scene B, that padding provided by fitsSystemWindows is lost and the content jumps up. Scene A loses the padding too, when returning.

Any assistance greatly appreciated with how to keep this padding through the transitions.

4

1 回答 1

1

好的,所以与场景转换无关,与android:fitsSystemWindows.

使用的任何视图的默认行为是使用android:fitsSystemWindows它传递的窗口插图。插图首先传递深度 - 请参阅此博客

所以在我上面的例子中,第一个场景 - 已经设置android:fitsSystemWindows消耗了插图,所以场景 B 没有机会。同样,当我转换回场景 A 时(它们已经被消耗掉了)。

我的示例中的修复是android:fitsSystemWindows从两个场景中删除并将其放置在场景根目录中。

于 2016-11-10T13:55:28.310 回答