我有一个在 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布局相同。
在 Activity 中,调用 ViewCompat.setOnApplyWindowInsetsListener(frameLayout, (v, insets) -> insets);
以将 fitsSystemWindows
与 FrameLayout 一起使用。
View 在初始 View 膨胀时是正确的,即 View 绘制在状态栏下方,但内容被窗口插入向下推以避免状态栏。
但是,当我转换到场景 B 时,fitsSystemWindows 提供的填充丢失了,内容跳了起来。返回时,场景 A 也丢失了填充。
非常感谢有关如何在过渡期间保持此填充的任何帮助。
最佳答案
好的,所以与场景转换无关,而与 android:fitsSystemWindows
有关。
任何使用 android:fitsSystemWindows
的 View 的默认行为是使用它传递的窗口插图。插图首先向下传递深度 - 请参阅此 blog .
所以在我上面的例子中,第一个场景 - 设置了 android:fitsSystemWindows
消耗了插图,所以场景 B 没有机会。同样,当我转换回场景 A 时(它们已经被消耗掉)。
我的示例中的修复是从两个场景中删除 android:fitsSystemWindows
并将其放在场景根目录中。
关于android - 通过 Scene Transition 维护 "fitsSystemWindows"窗口插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40512315/