在沉浸式粘滞模式下,如何拉伸片段的布局以填充屏幕?

时间:2014-07-03 15:03:33

标签: android android-fragments

我在Immersive Sticky Mode中的片段布局有问题。系统栏和导航栏正确消失,但片段布局不会拉伸以填充之前占据的空间。

这是一个屏幕截图,展示了我在说什么:

enter image description here

红色是活动的背景,蓝色是片段的。

这就是我如何启动沉浸式粘滞模式(来自Activity,就在加载碎片之前):

public void startImmersiveMode()
{
    getWindow().getDecorView().setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
        View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
        View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
        View.SYSTEM_UI_FLAG_FULLSCREEN |
        View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}

如何让Fragment扩展以涵盖活动?

编辑 - 这是一些XML:

的活动:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:background="@color/red"/>

片段:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container_view"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_blue_bright"
    android:gravity="center">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"/>

</LinearLayout>

1 个答案:

答案 0 :(得分:6)

罪魁祸首是活动布局中的android:fitsSystemWindows="true"。删除后,片段展开以占据整个窗口。