So I recently moved to constraint layouts, but I can't figure this one out. So here is my code:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".dashboard.DashboardActivity">
<FrameLayout
android:id="@+id/dashboard_framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/dashboard_bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/dashboard_framelayout"
app:menu="@menu/menu_dashboard_bottom_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
And this is what it looks like
So what do I do wrong in my code? I set the constraint of the BottomNavigationView to parent, but somehow it gets pushed further down and I have no clue how to fix this.
That does work, but your bottom nav will overlay the FrameLayout. If that's what you want, then fine. If you don't want it to overlay, do the following:
In FrameLayout, change layout_height=0dp
to match constraints. Also add the following constraint: app:layout_constraintBottom_toTopOf="@id/dashboard_bottom_navigation
In BottomNavigationView you don't have to do anything. You can leave the top constraint (which will chain the two views) or remove it. Either way, if you hide the NavView, the FrameLayout will expand to fill the screen and shrink when the NavView is shown.