android - Fab Button 在 Fling 上使用 HideOnScroll 覆盖 BottomAppBar - 可能是一个错误
问题描述
我正在FabButton
使用BottomAppBar
. 布局由 a 组成,RecyclerView
问题是当用户滚动滚动时RecyclerView
,FabButton
覆盖BottomAppBar
并需要 3-10 秒才能自动重置。RecyclerView
当滚动一点点或缓慢滚动时,不会发生此行为。但是,对于用户来说,这看起来像是一个错误的行为。看看它,看看是否有可能的解决方案。
我正在使用HideOnScroll
属性 astrue
并更改隐藏或出现的FabAlignment
时间End
和Center
时间。它工作正常,当我没有将它与隐藏时BottomAppBar
对齐时,这个错误不会出现,但我想要那个。FabButton
BottomAppBar
你可以在这里观看问题:视频 - Imgur
XML 布局
<androidx.coordinatorlayout.widget.CoordinatorLayout android:id="@+id/coordinatorView" android:layout_width="match_parent" android:layout_height="match_parent"> <include layout="@layout/sample_layout" android:layout_width="match_parent" android:layout_height="match_parent" /> <com.google.android.material.bottomappbar.BottomAppBar android:id="@+id/bottomBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:clickable="false" app:contentInsetStart="0dp" app:contentInsetStartWithNavigation="0dp" app:fabAlignmentMode="center" app:hideOnScroll="true"/> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/fabButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:backgroundTint="@color/white" android:src="@drawable/ic_baseline_add_24" app:tint="@color/colorPrimary" app:layout_anchor="@id/bottomBar"/> </androidx.coordinatorlayout.widget.CoordinatorLayout>
科特林代码:
recyclerView.setOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { super.onScrolled(recyclerView, dx, dy) if (dy > 0) bottomBar.fabAlignmentMode = BottomAppBar.FAB_ALIGNMENT_MODE_END else if (dy < 0) bottomBar.fabAlignmentMode = BottomAppBar.FAB_ALIGNMENT_MODE_CENTER } })
而且他们没有提供fabCradleVerticalOffset
动态更改它的属性。
解决方案
if (dy > 0)
bottomBar.fabAlignmentMode = BottomAppBar.FAB_ALIGNMENT_MODE_END
else if (dy < 0)
bottomBar.fabAlignmentMode = BottomAppBar.FAB_ALIGNMENT_MODE_CENTER
在这行代码中,当列表垂直滚动时,fab 图标将移动到末尾,如果没有滚动,它将移动到中心,所以我认为你应该更改这行代码或者只是没有它就可以工作。
推荐阅读
- node.js - 声明类型既不是“void”也不是“any”的函数必须返回一个值。ts Typescript
- c# - dml 命令可以在运行时在一个数据库上使用两次吗?
- python - 给定包含集合 S 中元素的元组集合 t,构建另一个成员不包含在 t 中的集合的最有效方法是什么?
- laravel - 如何将 Laravel Mix Build 通知窗口移动到页面底部
- ios - 在普通系统中以 react-native 为 ios 创建发布应用程序
- c - 为什么我的窗口只有在我使用 SDL_PollEvent() 后才会显示?
- java - IBM MobileFirst Adapter 接受 Multipart 请求
- icu - 为什么 ICU 对日期的“独立”值有区别?
- r - 如何(在R中)根据先前值除以当前值的计算来改变新列(这些值都在现有列中)
- javascript - 如何改进这个 js 功能,使其更快,更好的单元测试?