aurelhubert / ahbottomnavigation

A library to reproduce the behavior of the Bottom Navigation guidelines from Material Design.
3.84k stars 683 forks source link

Bottom navigation doesn't stay at bottom? #321

Open anta40 opened 6 years ago

anta40 commented 6 years ago

Not really sure whether the cause of this bug is mine, or something inside AHBottomNavigation. I'll give a shot, anyway.

So, I'm using the latest AHBottomNavtion (2.2.0). It's defined in my content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="net.devbyzero.app.pascatrisakti.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <FrameLayout
        android:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- bottom navigation -->
    <com.aurelhubert.ahbottomnavigation.AHBottomNavigation
        android:id="@+id/bottom_navigation"
        android:layout_gravity="bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</android.support.constraint.ConstraintLayout>

The result is, well AHBottomNavigation (Berita,Kalender,Kontak) stays on top, which is supposed to be at bottom. The full source code is provided. Feel free to give it a look :)

spt

bismert commented 6 years ago

Hi @anta40, may be you should try having your AHBottomNavigation contained in a coordinatorLayout for best result

`<?xml version="1.0" encoding="utf-8"?> <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/home_coordinator_layout_id" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/scblur">

<FrameLayout
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</FrameLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/home_fab_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:layout_marginBottom="64dp"
    android:layout_marginRight="16dp"
    android:src="@drawable/ic_write"
    android:tint="@android:color/white" />

<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
    android:id="@+id/home_bottom_navigation_id"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom" />

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

easycheese commented 6 years ago

@anta40 If you are using ConstraintLayout you need to use the constraint layout rules. This is my code:

<android.support.constraint.ConstraintLayout 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"
                                         xmlns:ads="http://schemas.android.com/apk/res-auto"
                                         android:layout_width="match_parent"
                                         android:layout_height="match_parent"
                                         tools:context="com.companionfree.kdmgenerator.main.MainActivity">

<com.google.android.gms.ads.AdView
    android:id="@+id/main_adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="@string/main_banner"
    android:visibility="gone"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toTopOf="@id/bottom_navigation"/>

<FrameLayout
    android:id="@+id/main_content"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintBottom_toTopOf="@+id/main_adView"
    app:layout_constraintTop_toTopOf="parent"/>

<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
/>

</android.support.constraint.ConstraintLayout> `