我有一个ToolBar并Recyclerview包裹在一个Coordinatorlayout. RecyclerView 填充了来自我们 api 的消息,并从底部堆叠。(就像一个聊天应用程序)
 //Set the layout manager
 LinearLayoutManager layoutManager = new LinearLayoutManager(requireContext());
 layoutManager.setStackFromEnd(true);
 layoutManager.setReverseLayout(true);
 binding.listMessages.setLayoutManager(layoutManager);
我想ReverseScrollBehavior通过覆盖AppBarLayout.ScrollingViewBehavior来反转它的行为来定义一个自定义。所以当我向上滚动时,工具栏会隐藏,当我向下滚动(到底部)时,工具栏会显示。
<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/list_messages"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none"
    app:stackFromEnd="true"
    app:reverseLayout="true"
    app:layout_behavior="com.rootsoft.kot.utils.ReverseScrollBehavior" />
我想为此使用ScrollingViewBehavior而不是覆盖onTouch 
更新
我想要实现的是获得当前appbar_scrolling_view_behavior. 想象一下有一个聊天应用程序,其中最新的消息从底部开始。当你向上滚动时,我想隐藏工具栏。AppBarLayout 的当前情况是当您向上滚动时,工具栏会显示,而当您向下滚动时,它会隐藏。我的滚动标志是:app:layout_scrollFlags="scroll|enterAlways|snap"
您需要创建一个方法来获取屏幕的高度和滚动事件(向上和向下)。您还可以在该方法中切换可见性。这意味着您将在 XML 中将可见性设置为可见,并执行以下操作:
    ChatButton Button;
    ChatButtton.setVisibility = View.GONE 
    ChatButton.setVisibility = View.VISIBLE
根据滚动事件处理可见性的切换
| 归档时间: | 
 | 
| 查看次数: | 346 次 | 
| 最近记录: |