Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BottomNavigationView with FloatingActionButton inside CoordinatorLayout dont match position

I want to hide my bottom bar on scroll but a FAB should stay on the screen.

If I put the FAB on top of BottomNavigationView using anchors but it appears behind it.

If I put layout_insetEdge="bottom" to the BottomNavigationView then it works but make my tests fail (https://issuetracker.google.com/issues/70162122) so I cannot use that at the moment.

enter image description here

Layout:

<?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"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/mainLayout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true"
  tools:context=".screens.main.MainActivity">

  <FrameLayout
    android:id="@+id/mainContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/scrolling_view_behaviour" />

  <android.support.design.widget.FloatingActionButton
    android:id="@+id/mainNewQuestionButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/spacing_8dp"
    app:layout_anchor="@+id/mainBottomNavigationView"
    app:layout_anchorGravity="top|right|end"
    app:srcCompat="@drawable/create_question"
    tools:visibility="visible" />

  <android.support.design.widget.BottomNavigationView
    android:id="@+id/mainBottomNavigationView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:itemBackground="@color/my_gray"
    app:itemIconTint="@drawable/selector_bottombar_item"
    app:itemTextColor="@drawable/selector_bottombar_item"
    app:layout_anchor="@id/mainContainer"
    app:layout_anchorGravity="bottom"
    app:layout_behavior="@string/hide_bottom_navigation_view_behaviour"
    app:menu="@menu/bottom_navigation_main" />

</android.support.design.widget.CoordinatorLayout>
like image 463
Daniel Gomez Rico Avatar asked Sep 01 '25 16:09

Daniel Gomez Rico


1 Answers

Just use:

<androidx.coordinatorlayout.widget.CoordinatorLayout>

 <com.google.android.material.bottomnavigation.BottomNavigationView
      android:id="@+id/bottom_navigation"
      android:layout_gravity="bottom"
      .../>

  <com.google.android.material.floatingactionbutton.FloatingActionButton
      android:layout_gravity="top"
      app:layout_anchor="@id/bottom_navigation"
      app:layout_anchorGravity="top|end"
      />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

enter image description here

like image 119
Gabriele Mariotti Avatar answered Sep 04 '25 08:09

Gabriele Mariotti