(Android) 什么是 RecyclerView.State 以及如何将它与 smoothScrollToPosition(recyclerView, state, position) 一起使用?

(Android) What is RecyclerView.State and how would one use it with smoothScrollToPosition(recyclerView, state, position)?

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

我已经知道的解决此问题的一种方法是自行初始化 smoothScroller,但我无法使用自定义 layoutManager 执行此操作,因为它仅更改方法 smoothScrollToPosition 并且不会受到单独的 smoothScroller 的影响.

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

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

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