Set container layout above BottomNavigationView

Viewed 2210

I have this layout. This layout contains BottomNavigationView and container for nested fragments

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="client.MainActivity">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />

</android.support.constraint.ConstraintLayout>

How can I set app_bar_main above BottomNavigationView top?

because now:

enter image description here BottomNavigationView cross with

2 Answers

The BottomNavigationDrawer is a View, so you may layout it as with:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include
    android:layout_weight="1""
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="0dp" />

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/windowBackground"
    app:menu="@menu/navigation" />

</LinearLayout>

Note that I replaced with a LinearLayout and filled the content_view for the remaining space of the screen.

If you want to use ConstraintLayout (doesnt requires for your layout) the solution would be have a id in the content_view and make it above navigation and below parent

Related