You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

BottomNavigation遮挡DrawerLayout中FrameLayout内容的问题求助

解决Fragment内容被BottomNavigationView遮挡的问题

问题根源

你的FrameLayout设置了match_parent高度,而BottomNavigationView覆盖在它上方,导致Fragment中的底部内容被遮挡。

修复方案(基于原RelativeLayout布局)

只需给FrameLayout添加底部约束,让它的底部停在BottomNavigationView上方即可:

  • 给FrameLayout添加android:layout_above="@id/bottom_navigation_ID"属性
  • 移除FrameLayout上无效的app:layout_behavior="@string/appbar_scrolling_view_behavior"(该行为仅配合AppBarLayout使用,当前布局无AppBarLayout,属性无意义)
  • 移除BottomNavigationView上的android:layout_gravity="bottom|end"(RelativeLayout布局下该属性无效)

修改后的核心布局代码:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/bottom_navigation_ID" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation_ID"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="?android:attr/windowBackground"
        app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
        android:foreground="?attr/selectableItemBackground"
        app:itemIconTint="@color/bottom_navigation_color"
        app:labelVisibilityMode="unlabeled"
        app:menu="@menu/navigation"/>
</RelativeLayout>

备选方案:改用ConstraintLayout布局

如果更倾向于ConstraintLayout,替换外层RelativeLayout为ConstraintLayout后,设置FrameLayout的约束:

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@id/bottom_navigation_ID" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation_ID"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        android:background="?android:attr/windowBackground"
        app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
        android:foreground="?attr/selectableItemBackground"
        app:itemIconTint="@color/bottom_navigation_color"
        app:labelVisibilityMode="unlabeled"
        app:menu="@menu/navigation"/>
</androidx.constraintlayout.widget.ConstraintLayout>

设置后,FrameLayout会自动填充底部导航上方的所有空间,Fragment内容就不会被遮挡了。

内容的提问来源于stack exchange,提问作者developer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 18:57:52