【问题标题】:Maintaining "fitsSystemWindows" window insets through Scene Transition通过场景转换维护“fitsSystemWindows”窗口插图
【发布时间】:2016-11-09 17:02:51
【问题描述】:

我有一个在 2 个场景之间转换的布局。

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>

场景 B 布局相同。

在活动中,调用ViewCompat.setOnApplyWindowInsetsListener(frameLayout, (v, insets) -&gt; insets); 以将fitsSystemWindows 与FrameLayout 一起使用。

视图在初始视图膨胀时是正确的,即视图是在状态栏下绘制的,但内容被窗口插入下推以避免状态栏。

但是,当我转换到场景 B 时,fitsSystemWindows 提供的填充丢失并且内容会跳起来。返回时,场景 A 也会丢失填充。

非常感谢任何有关如何在过渡中保持此填充的帮助。

【问题讨论】:

    标签: android transitions android-constraintlayout


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多