Search code examples
androidandroid-layoutandroid-recyclerviewscrollviewsmooth-scrolling

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


This issue is probably really simple but I can't possibly be the only one totally confused and it's driving me crazy. My question is very simple: what is RecyclerView.State and how can I use this with the method smoothScrollToPosition. I've seen threads where people that used smoothScrollToPosition did not need State, but it [the method smoothScrollToPosition] appears to only work with 3 arguments (RecyclerView, RecyclerView.State, and position). The first and last arguments are easy, but what the heck is RecyclerView.State??? Is there a way around this, what should I be putting in that field?

One way around this that I already know of is to initialize a smoothScroller by itself, but I can't do that with my custom layoutManager because it changes the method smoothScrollToPosition only and wouldn't be affected by a separate smoothScroller.


Solution

  • You are trying to call smoothScrollToPosition at LayoutManager. Try to call at your RecyclerView object.

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

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