【发布时间】:2021-08-23 08:46:03
【问题描述】:
我有一个带有 RecyclerView 和 Fab 按钮的 CoordinatorLayout。
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeChatRoomRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/chatRoomRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
android:scrollbars="vertical" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/bottomScrollFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="12dp"
android:src="@drawable/ic_arrow_down"
app:backgroundTint="@color/colorPrimaryLight"
app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"
app:layout_anchor="@id/swipeChatRoomRecycler"
app:layout_anchorGravity="bottom|right|end"
app:fabSize="mini" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
recyclerView设置如下
viewManager = LinearLayoutManager(activity).apply {
orientation = LinearLayoutManager.VERTICAL
stackFromEnd = false
reverseLayout = true
}
我想要实现的是
- 在活动启动时,我希望
bottomScrollFab不可见,因为默认情况下回收器最终滚动
- 我想实现完全相反的行为,这意味着我希望 Fab 在回收器未 onScroll 时显示,并在回收器 onScroll 时隐藏
这两件事我该怎么做?
【问题讨论】:
标签: android android-recyclerview android-coordinatorlayout material-components-android