kylas
kylas

Reputation: 1455

BottomNavigationView overlaps with last item

My XML layout as below:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinatorLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <!-- AppBar Layout   -->
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="fill_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
            <Button
                android:id="@+id/filter_location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                style="?android:attr/borderlessButtonStyle"
                android:drawableRight="@drawable/ic_filter_list_white_24dp"
                android:layout_gravity="right"
                />
        </android.support.v7.widget.Toolbar>
        <!-- Tab Layout for creating tabs -->
        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </android.support.design.widget.AppBarLayout>
    <!-- Helps handing the Fragments for each Tab -->
    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/float_search"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginBottom="70dp"
        android:src="@android:drawable/ic_menu_search" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@color/colorPrimary"
        app:itemBackground="@color/colorPrimary"
        app:itemIconTint="@color/windowBackground"
        app:itemTextColor="@color/windowBackground"
        app:menu="@menu/bottom_navigation_main" />
</android.support.design.widget.CoordinatorLayout>

The BottomNavigationView overlaps with the last item in the content. How should I fix this ? How can I make the last item above the BottomNavigation bar ? I have tried adding linear layout inside but still did not work.

Upvotes: 7

Views: 3825

Answers (6)

Mohamed Niyaz
Mohamed Niyaz

Reputation: 228

Add this one line in the coordinator layout:

android:layout_marginBottom="?attr/actionBarSize"

and it will work

Upvotes: 2

JinSun
JinSun

Reputation: 1

Try to add this

app:layout_insetEdge="bottom"

in BottomNavigationView

Upvotes: 0

mbmyke
mbmyke

Reputation: 111

Use this xml

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

<LinearLayout 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"
android:orientation="vertical">

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/coordinatorLayout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">

<!-- AppBar Layout   -->
<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="fill_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
        <Button
            android:id="@+id/filter_location"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="?android:attr/borderlessButtonStyle"
            android:drawableRight="@drawable/ic_filter_list_white_24dp"
            android:layout_gravity="right"
            />
    </android.support.v7.widget.Toolbar>
    <!-- Tab Layout for creating tabs -->
    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<!-- Helps handing the Fragments for each Tab -->
<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/float_search"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginBottom="40dp"
    android:src="@android:drawable/ic_menu_search" />

</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

</android.support.design.widget.CoordinatorLayout>

</LinearLayout>

Upvotes: 0

Shreya Patel
Shreya Patel

Reputation: 94

Try to put it in Relative layout and use the below property in view pager.

android:layout_below="@+id/bottom_navigation"

Upvotes: 2

Anurag Singh
Anurag Singh

Reputation: 6190

Remove android:layout_gravity="bottom" from android.support.design.widget.BottomNavigationView and add the following

app:layout_anchor="@+id/viewPager"
app:layout_anchorGravity="bottom"

in android.support.design.widget.BottomNavigationView

Upvotes: 1

Chetan Joshi
Chetan Joshi

Reputation: 5711

Replace your xml with below xml:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinatorLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <!-- AppBar Layout   -->
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="fill_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

            <Button
                android:id="@+id/filter_location"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:drawableRight="@drawable/border" />
        </android.support.v7.widget.Toolbar>
        <!-- Tab Layout for creating tabs -->
        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </android.support.design.widget.AppBarLayout>
    <!-- Helps handing the Fragments for each Tab -->
    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="fill_parent"
        android:layout_height="354dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/float_search"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginBottom="70dp"
        android:src="@android:drawable/ic_menu_search" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@color/colorPrimary"
        app:itemBackground="@color/colorPrimary"
        app:itemIconTint="@color/colorAccent"
        app:itemTextColor="@color/colorPrimaryDark" />
</android.support.design.widget.CoordinatorLayout>

Upvotes: 0

Related Questions