如何确保 CoordinatorLayout 子项不重叠

Mus*_*lla 6 android material-design android-coordinatorlayout android-bottomappbar

我在协调器布局内使用底部应用栏。其余内容来自片段。片段内容被底部应用栏覆盖

因为我使用的是 bottomAppBar,所以它必须在 CoordinatorLayout 内,并且所有孩子也必须在其中。BottomAppBar 上方的所有布局都应该填充提醒的空间,但如果我这样做,底部的视图就会被覆盖。如何确保视图不与 BottomAppBar 重叠

<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawerLayout_main"
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".main.MainActivity">

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/coordinatorLayout"
    android:layout_width="0dp"
    android:layout_height="wrap_content">

    </androidx.constraintlayout.widget.ConstraintLayout>

    <fragment
        android:id="@+id/fragment_main_navHost"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        android:layout_gravity="top"
        app:navGraph="@navigation/nav_graph"/>


    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:fabAlignmentMode="end"
        app:fabCradleMargin="4dp"
        app:hideOnScroll="true"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

<com.google.android.material.navigation.NavigationView
    android:id="@+id/navView_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/nav_header_layout"
    app:menu="@menu/main_navigation"/>
Run Code Online (Sandbox Code Playgroud)

我需要的是确保替换片段的任何内容都不应被底部应用栏覆盖,并且它应该使用底部应用栏未使用的所有空白区域。我是另一个世界,内容应该在它上面,同时使用其余的空白区域并且仍然在协调器布局内。

Mar*_*ari 2

只需添加margin到您的片段容器中:

  <fragment
    android:id="@+id/fragment_main_navHost"
    android:name="androidx.navigation.fragment.NavHostFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="{bottom_navigation_height}"
    android:layout_marginTop="{tool_bar_height}"
    app:defaultNavHost="true"
    android:layout_gravity="top"
    app:navGraph="@navigation/nav_graph"/>
Run Code Online (Sandbox Code Playgroud)