FrameLayout 未正确约束。它的底部隐藏在 BottomNavigationView 下

FrameLayout not correctly constrained. Bottom part of it gets hidden under BottomNavigationView

我的 activity 使用了多个片段,其中包含 RecyclerView。这里的 FrameLayout 是片段的容器。问题是,尽管我将 FrameLayout 的底部设置为 BottomNavigationView 的顶部,但 RecyclerView 的最后一个元素隐藏在 BottomNavigationView 下。

我的 activity 布局代码:

<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ToolbarTheme"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:logo="@drawable/money_icon"
    />

<FrameLayout
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/toolbar"
    app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"/>

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bottomNavigationView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:menu="@menu/bottom_nav_menu" />

片段代码包括 RecyclerView:

<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:background="@color/dark_gray"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/finishedSlipsRecycler"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:visibility="gone"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

</androidx.recyclerview.widget.RecyclerView>

问题截图:

显然问题出在这一行:

app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"

去掉就好了

编辑:

将您的ConstraintLayout替换为

Code for fragment includes RecyclerView:

by FrameLayout 因为它只包含一个元素。我认为像这样将 ConstraintLayout 放在 FrameLayout 中是有问题的。

实际是RecyclerView流过FrameLayout引起的问题。更好的定义和问题的答案可以找到