【问题标题】:(Android) What is RecyclerView.State and how would one use it with smoothScrollToPosition(recyclerView, state, position)?(Android) 什么是 RecyclerView.State 以及如何将它与 smoothScrollToPosition(recyclerView, state, position) 一起使用?
【发布时间】:2018-10-25 00:07:36
【问题描述】:

这个问题可能真的很简单,但我不可能是唯一一个完全困惑的人,这让我发疯了。我的问题很简单:什么是 RecyclerView.State 以及如何将其与方法 smoothScrollToPosition 一起使用。我见过使用smoothScrollToPosition 的人不需要State 的线程,但它[smoothScrollToPosition 方法] 似乎只适用于3 个参数(RecyclerView、RecyclerView.State 和 position)。第一个和最后一个参数很简单,但 RecyclerView.State 到底是什么?有没有办法解决这个问题,我应该在那个领域放什么?

我已经知道的一种解决方法是自己初始化一个 smoothScroller,但我不能用我的自定义 layoutManager 这样做,因为它只更改方法 smoothScrollToPosition 并且不会受到单独的 smoothScroller 的影响。

【问题讨论】:

    标签: android android-layout android-recyclerview scrollview smooth-scrolling


    【解决方案1】:

    您正在尝试在 LayoutManager 中调用 smoothScrollToPosition。尝试调用您的 RecyclerView 对象。

    recyclerView.smoothScrollToPosition(5); // Scroll to 5 item
    

    文档 - https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html#smoothScrollToPosition(int)

    【讨论】:

    • 好吧!这就是问题所在,现在一切都解决了。挽回面子并删除问题很诱人,但我会留下它:D。另一种方法是我刚刚意识到确实涉及编辑 LayoutManager,方法是覆盖扩展 LinearSmoothScroller 的类中的一些方法。非常感谢!
    猜你喜欢
    • 2010-12-09
    • 2010-12-25
    • 2016-09-10
    • 1970-01-01
    • 2015-06-24
    • 2023-04-07
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    相关资源
    最近更新 更多