Fragment Content Overlaps Toolbar and Bottom Navigation View Fragment Content Overlaps Toolbar and Bottom Navigation View xml xml

Fragment Content Overlaps Toolbar and Bottom Navigation View


Add margins to container:

<FrameLayout    android:id="@+id/container"    android:layout_width="match_parent"    android:layout_above="@+id/navigationView"    android:layout_height="match_parent"    android:layout_marginBottom="{bottom_navigation_height}"    android:layout_marginTop="{tool_bar_height}"   />


I removed from my ConstraintLayout the default generated marginTop field, and changed my fragment's layout_height to 0dp. Then in all of my Fragments' layout's the outermost layout_height I always set to match parent.

<?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"    android:id="@+id/container"    android:layout_width="match_parent"    android:layout_height="match_parent">    <com.google.android.material.bottomnavigation.BottomNavigationView        android:id="@+id/nav_view"        android:layout_width="0dp"        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" />    <fragment        android:id="@+id/nav_host_fragment"        android:name="androidx.navigation.fragment.NavHostFragment"        android:layout_width="match_parent"        android:layout_height="0dp"        app:defaultNavHost="true"        app:layout_constraintBottom_toTopOf="@id/nav_view"        app:layout_constraintLeft_toLeftOf="parent"        app:layout_constraintRight_toRightOf="parent"        app:layout_constraintTop_toTopOf="parent" /></androidx.constraintlayout.widget.ConstraintLayout>


You should add constraints to your @id/container.To the top to your toolbar and to the bottom to the BottomNavigationBar. The same should you do to these elements. Toolbar top to parent and toolbar bottom to container. BottomNavigationBar top to container and bottom to parent. Then set the height of the container to 0dp.

<include layout="@layout/toolbar"    android:id="@+id/toolbar"    android:layout_width="0dp"    android:layout_height="?attr/actionBarSize"    app:layout_constraintTop_toTopOf="parent"    app:layout_constraintEnd_toEndOf="parent"    app:layout_constraintStart_toStartOf="parent"/><FrameLayout    android:id="@+id/container"    android:layout_width="0dp"    android:layout_height="0dp"    app:layout_constraintBottom_toBottomOf="@+id/navigationView"    app:layout_constraintTop_toTopOf="@id/toolbar"    app:layout_constraintEnd_toEndOf="parent"    app:layout_constraintStart_toStartOf="parent"/><android.support.design.widget.BottomNavigationView    android:id="@+id/navigationView"    android:layout_width="0dp"    android:layout_height="wrap_content"    app:layout_constraintBottom_toBottomOf="parent"    app:layout_constraintLeft_toLeftOf="parent"    app:layout_constraintRight_toRightOf="parent"/>

Didn't test the code but should work.