【发布时间】:2021-07-20 05:42:43
【问题描述】:
我正在开发一款安卓游戏。它由一个主要活动和几个片段组成,通过它们的导航是通过导航组件处理的。我有一个小问题让我发疯。主要活动正确设置全屏,状态和按钮栏正确隐藏,我选择的背景图像完全全屏显示。相反,说到片段,它们的元素似乎隐藏在状态栏下方,或者布局的大小不符合屏幕的实际大小。如果我在布局的最底部放置一个按钮,如您在此screenshot 中看到的那样,屏幕上实际发生的是this(请注意,该按钮被剪切到按钮栏应该在的位置)。我使用android studio中提供的全屏片段作为模型,这些是其中使用的标志。
int flags = View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
我也尝试在片段的根布局中添加android:fitsSystemWindows="true",但没有奏效。
编辑
问题是由非全屏的 FragmentContainerView 引起的。我尝试将背景设置为它而不是其父级,并且图像已被剪切:screenshot
主要的activity布局是:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/colourful_sound_waves_pattern_phone_wallpaper__1_"
android:theme="@style/ThemeOverlay.LOCAL.FullscreenContainer"
tools:context=".FullscreenActivity"
android:id="@+id/frame_layout">
<FrameLayout
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
android:fitsSystemWindows="true">
<androidx.fragment.app.FragmentContainerView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
<LinearLayout
android:id="@+id/fullscreen_content_controls"
style="@style/Widget.Theme.LOCAL.ButtonBar.Fullscreen"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom|center_horizontal"
android:orientation="horizontal"
tools:ignore="UselessParent">
</LinearLayout>
</FrameLayout>
</FrameLayout>
【问题讨论】:
-
你能分享你的活动布局xml吗?
-
我已经发布了布局!
标签: android android-layout android-fragments android-view android-fullscreen