BottomNavigationView with FloatingActionButton inside CoordinatorLayout does not match position

I want to hide the bottom scroll bar, but the FAB should remain on the screen.

If I put FABon top BottomNavigationViewwith the help of anchors, but he will appear behind him.

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

enter image description here

Markup:

<?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>
+3
source share
2 answers

, Z-Ordering. fab.bringToFront(), fab.invalidate() api 21 ViewCompat.setZ(fab, someFloat) api 21.

FloatingActionMenu, FAB, , , .

+1

:

<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

0

Source: https://habr.com/ru/post/1673656/


All Articles