【问题标题】:Reverse AppBarLayout.ScrollingViewBehavior反向 AppBarLayout.ScrollingViewBehavior
【发布时间】:2018-11-14 14:56:38
【问题描述】:

我有一个 ToolBarRecyclerview 包裹在 Coordinatorlayout 中。 RecyclerView 填充了来自我们 api 的消息,并从底部堆叠。 (就像一个聊天应用程序)

 //Set the layout manager
 LinearLayoutManager layoutManager = new LinearLayoutManager(requireContext());
 layoutManager.setStackFromEnd(true);
 layoutManager.setReverseLayout(true);
 binding.listMessages.setLayoutManager(layoutManager);

我想通过覆盖AppBarLayout.ScrollingViewBehavior 来定义自定义ReverseScrollBehavior 以反转它的行为。 因此,当我向上滚动时,工具栏会隐藏,而当我向下滚动(到底部)时,工具栏会显示。

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

【问题讨论】:

  • 我只是想和当前的appbar_scrolling_view_behavior 做相反的事情。想象有一个聊天应用程序,其中最新消息从底部开始。当您向上滚动时,我想隐藏工具栏。 AppBarLayout 的当前情况是,当您向上滚动时,会显示工具栏。我的滚动标志是:app:layout_scrollFlags="scroll|enterAlways|snap"
  • @Cheticamp 我已经创建了一个扩展 AppBarLayout.Behavior 的 ReverseScrollBehavior,但我不知道要覆盖哪些方法以实现 .我在找。
  • 我认为appbar_scrolling_view_behavior 的剂量与您想要的相同。 当你向上滚动时,它会隐藏工具栏。
  • @RumitPatel 这取决于向上滚动的上下文。我的意思是当内容向上滚动时。因此,当您将手指从中心拖动到底部时,向上滚动内容,我想隐藏工具栏。

标签: android


【解决方案1】:

您需要创建一个方法来获取屏幕高度和滚动事件(向上和向下)。您还可以在方法中切换可见性。 这意味着您将在 XML 中将可见性设置为可见并执行以下操作:

    ChatButton Button;

    ChatButtton.setVisibility = View.GONE 
    ChatButton.setVisibility = View.VISIBLE

根据滚动事件处理可见性的切换

【讨论】:

  • 我知道如何使用滚动监听器来做到这一点。我更喜欢使用 ScrollingViewBehavior 方法。
猜你喜欢
  • 1970-01-01
  • 2019-05-02
  • 2017-02-22
  • 2017-08-18
  • 2014-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-15
相关资源
最近更新 更多