【问题标题】:BottomAppBar And FloatingActionButton app:layout_scrollFlags behaviorBottomAppBar 和 FloatingActionButton 应用程序:layout_scrollFlags 行为
【发布时间】:2018-11-04 00:03:47
【问题描述】:

我目前在我的布局中使用了 BottomAppBar 和 FloatingActionButton 的组合(显然在 CoordinatorLayout 内部):请参阅布局:

  <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:backgroundTint="@color/primarycolor"
        app:theme="@style/ThemeOverlay.MaterialComponents.Dark"
        app:fabAlignmentMode="center"
        app:layout_scrollFlags="scroll|enterAlways"
        app:navigationIcon="@drawable/ic_menu_time" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|enterAlways"
        app:backgroundTint="#FFFF0000"
        app:layout_anchor="@id/bar"
        app:rippleColor="#FFFF8888"
        app:srcCompat="@drawable/ic_fab_search" />

列表滚动的行为就像 BottomAppBar 的魅力一样,但我对 FloatingActionButton 有很大的问题。

正如您在下面的屏幕截图中看到的那样,BottomAppBar 完全消失了,这很棒,但是对于 FAB,我无法获得相同的效果。它只是在底部移动了一点。

知道我可以从哪里着手解决这个问题吗?正确的行为是 FAB 跟随 Bar 并简单地消失

滚动之后:

【问题讨论】:

标签: android floating-action-button coordinator-layout android-bottomappbar


【解决方案1】:

您应该自己隐藏 FAB。只需致电 fab.hide()fab.show() 即可管理其可见性。

【讨论】:

  • 使用格式化工具使您的帖子更具可读性。使用code blocking 表示代码、日志和错误文本,使用 bolditalics 突出显示内容
猜你喜欢
  • 1970-01-01
  • 2020-09-18
  • 2021-12-14
  • 2021-02-09
  • 1970-01-01
  • 1970-01-01
  • 2017-07-15
  • 2021-06-17
  • 2016-05-05
相关资源
最近更新 更多