因此,我正在开发一个使用FrameLayout作为片段容器的应用程序,其内容取决于底部导航器中的选定项目。我的问题是,由于某种原因,我无法使FrameLayout适应整个屏幕,因此,每当我运行该应用程序时,我始终在片段上方有一个空白区域。我试图更改长度,更改边距,但似乎无济于事。我想念什么?这是代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintHorizontal_bias="0.038"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.094" />
</androidx.constraintlayout.widget.ConstraintLayout>
这是结果:
提前感谢!
您的ConstraintLayout
具有顶部填充,因此孩子将永远无法到达顶部。
如果要全屏显示,请将其从ConstraintLayout
中删除
android:paddingTop="?attr/actionBarSize