本文介绍了在CoordinatorLayout中带有FloatingActionButton的BottomNavigationView与位置不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在滚动条上隐藏我的底部栏,但FAB应该留在屏幕上.

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

如果我使用锚将FAB放在BottomNavigationView的顶部,但它出现在其后面.

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

如果我将layout_insetEdge="bottom"放在BottomNavigationView上,则可以使用,但会使我的测试失败( https ://issuetracker.google.com/issues/70162122 ),所以我目前无法使用它.

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.

布局:

<?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>

推荐答案

您似乎在这里遇到了Z-Ordering问题.对于低于21的api,您可以尝试fab.bringToFront(),然后按fab.invalidate(),对于高于21的api,可以尝试ViewCompat.setZ(fab, someFloat).

You seem to be having a Z-Ordering issue here.You could try the fab.bringToFront() followed by fab.invalidate() for api's below 21, and ViewCompat.setZ(fab, someFloat) for api's above 21.

我使用这些方法将自定义FloatingActionMenu(由我为项目编写的一系列FAB组成)带到了前面,以便它们可以与屏幕上的所有内容重叠.

I used these methods to bring a custom FloatingActionMenu, consisting of a series of FAB's I wrote for a project, to the front so they would overlap everything on the screen.

这篇关于在CoordinatorLayout中带有FloatingActionButton的BottomNavigationView与位置不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-11 02:37