我在沉浸式粘滞模式下遇到 fragment 布局问题。系统栏和导航栏正确消失,但 Fragment 布局不会拉伸(stretch)以填充这些栏先前占据的空间。
这是展示我在说什么的截图:
红色是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/