【发布时间】: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) -> insets); 以将fitsSystemWindows 与FrameLayout 一起使用。
视图在初始视图膨胀时是正确的,即视图是在状态栏下绘制的,但内容被窗口插入下推以避免状态栏。
但是,当我转换到场景 B 时,fitsSystemWindows 提供的填充丢失并且内容会跳起来。返回时,场景 A 也会丢失填充。
非常感谢任何有关如何在过渡中保持此填充的帮助。
【问题讨论】:
标签: android transitions android-constraintlayout