Android | 使用BottomNavigationView 作为底部导航时会遮挡Fragment解决方案

在使用BottomNavigationView作为底部导航时导航栏一直浮在展示FragmentFrameLayout底部上层(想要的效果是FrameLayoutBottomNavigationViewverticalorientation排列)

最终代码:

<RelativeLayout 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:orientation="vertical"
    tools:context=".MainActivity">

    <FrameLayout
        android:id="@+id/mainContentFrame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/navigation"
        android:background="@color/white"
        app:layout_constraintBottom_toTopOf="@+id/navigation"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="UnknownId"
        tools:layout_editor_absoluteX="0dp" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        app:itemBackground="@color/blueGreen"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />

RelativeLayout>

你可能感兴趣的:(Android)