Johnny Orton
Johnny Orton

Reputation: 103

How to align BottomNavigationView to the bottom on an activity along with NavigationView?

I'm trying to implement BottomNavigationView along with NavigationView on the same activity but BottomNavigationView doesn't seem to go at the bottom.

As the BottomNavigationView is at the center of the activity. I browsed through the internet regarding this problem but didn't find any solution.

enter image description here

My XML code:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/main_content">

    <include layout="@layout/search_toolbar"/>


</RelativeLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/main_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:menu="@menu/navigation_menu"
    android:layout_gravity="start"
    app:itemTextColor="#e6000000"
    app:itemIconTint="#8c000000"
    app:headerLayout="@layout/navigation_header">
</android.support.design.widget.NavigationView>

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:itemBackground="@color/colorPrimary"
    app:menu="@menu/bottom_navigation" />

Error shown: onMeasureError

java.lang.IllegalStateException: Child android.support.design.widget.BottomNavigationView{64f98f6c V.E...... ......I. 0,0-0,0 #7f0c0080 app:id/bottom_navigation_bar} at index 2 does not have a valid layout_gravity - must be Gravity.LEFT, Gravity.RIGHT or Gravity.NO_GRAVITY
at android.support.v4.widget.DrawerLayout.onMeasure_Original(DrawerLayout.java:1112)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java)
at android.view.View.measure(View.java:19734)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:19734)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:19734)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:589)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:342)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:368)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:567)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:549)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:863)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:549)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$1(RenderTask.java:680)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Upvotes: 10

Views: 6190

Answers (1)

shmakova
shmakova

Reputation: 6426

Try this:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include layout="@layout/search_toolbar" />


        <android.support.design.widget.BottomNavigationView
            android:id="@+id/bottom_navigation_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:itemBackground="@color/colorPrimary"
            app:menu="@menu/bottom_navigation" />
    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/main_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/navigation_header"
        app:itemIconTint="#8c000000"
        app:itemTextColor="#e6000000"
        app:menu="@menu/navigation_menu" />

</android.support.v4.widget.DrawerLayout>

Upvotes: 14

Related Questions