Yunus Haznedar
Yunus Haznedar

Reputation: 1614

Why is my BottomBar in the middle of the screen?

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" />

Upvotes: 2

Views: 1736

Answers (3)

AshAR
AshAR

Reputation: 228

Try using either of the two=

android:layout_gravity="bottom"

or

android:gravity="bottom"

Upvotes: 1

Srikar Reddy
Srikar Reddy

Reputation: 3708

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"

Upvotes: 4

Abhijeet Kumar
Abhijeet Kumar

Reputation: 351

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

Upvotes: 0

Related Questions