How to align BottomNavigationView to bottom of activity along with NavigationView?

I am trying to implement BottomNavigationView

along with NavigationView

under the same activity but BottomNavigationView

doesn't seem to go at the bottom.

Because the BottomNavigationView is at the center of the activity. I have searched the internet for this problem but couldn't find a 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)

      

+3


source to share


1 answer


Try the following:



<?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>

      

+3


source







All Articles