android - 在沉浸式粘滞模式下,如何拉伸(stretch) Fragment 的布局以填满屏幕?

标签 android android-fragments

我在沉浸式粘滞模式下遇到 fragment 布局问题。系统栏和导航栏正确消失,但 Fragment 布局不会拉伸(stretch)以填充这些栏先前占据的空间。

这是展示我在说什么的截图:

enter image description here

红色是Activity的背景,蓝色是Fragment的。

下面是我启动沉浸式粘滞模式的方式(从 Activity,就在加载 Fragment 之前):

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 展开以覆盖 Activity?

编辑 - 这是一些 XML:

Activity :

<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"/>

fragment :

<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>

最佳答案

罪魁祸首是 Activity 布局中的 android:fitsSystemWindows="true"。在我删除它之后, fragment 展开以占据整个窗口。

关于android - 在沉浸式粘滞模式下,如何拉伸(stretch) Fragment 的布局以填满屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24557231/

相关文章:

java - Android Studio 链接引用失败

android - 使用 "so"文件创建一个 SDK(单个 jar 文件)

java - 将 Google map 添加到 fragment

android - fragment 动画 : Fatal signal 11 (SIGSEGV) Crash

android - AccountAuthenticatorActivity 和 Fragments

android如何滚动查看 View 的所有小部件

android - 如何使用应用程序获取 Android 手机(例如加速度计、陀螺仪、GPS、摄像头馈送)的传感器读数?

java - 使用 jsoup 解析脚本(JSON 数据)

java - 更新recyclerView

Java 堆栈 : Don't allow duplicates fragment entries into stack