2

I'm using both NavigationDrawer and BottomNavigationView. But after the add Navigation Drawer, position of Bottom Navigation is changed. How do I solve that? I assume this problem is caused by my xml files.

BottomBar

activity_main.xml

<android.support.v4.widget.DrawerLayout  xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
tools:context="com.example.yunus.ototakip.MainActivity">

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

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_navigation_bar"
    app:menu="@menu/activity_navigation_bar_drawer" />
<FrameLayout
    android:id="@+id/main_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true">
</FrameLayout>

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

Alex P.
  • 30,437
  • 17
  • 118
  • 169
Yunus Haznedar
  • 1,584
  • 4
  • 23
  • 33

3 Answers3

4

Attach your BottomNavigationView inside the CoordinatorLayout (or whatever view group you've inside app_bar_navigation_bar layout) not DrawerLayout and add appropriate gravity tag.

android:layout_gravity="bottom"
Srikar Reddy
  • 3,650
  • 4
  • 36
  • 58
1

Try using either of the two=

android:layout_gravity="bottom"

or

android:gravity="bottom"
AshAR
  • 228
  • 1
  • 14
0

use android:layout_gravity="bottom" instead of layout_alignParentBottom as it is for RelativeLayout not android.support.v4.widget.DrawerLayout.

Abhijeet Kumar
  • 343
  • 2
  • 8
  • I get this error:BottomNavigationView at index 3 does not have a valid layout_gravity - must be Gravity.LEFT, Gravity.RIGHT or Gravity.NO_GRAVITY – Yunus Haznedar Jan 18 '17 at 16:27