I am using horizontal layout manager for my RecyclerView
.
I need make RecyclerView
in next way: when click on some item - make smoothScrool to that position and put that item in the center of RecyclerView
(if it possible, for example 10 item from 20).
So, I have no problem with smoothScrollToPosition()
, but how to put item than in the center of RecyclerView
???
Thanks!
Yes it's possible.
By implementing
RecyclerView.SmoothScroller
's methodonTargetFound(View, State, Action)
.Specifically in
LinearLayoutManager
withLinearSmoothScroller
:since now(Feb 2019), I could easily use this code in ListView
RecyclerView not verified, I guess would be the same.
Improvements to the answer - there is no need to override the
LinearLayoutManager
From the previous answer:
Here how to use it:
Just in case someone needs the Kotlin equivalent of the class in the accepted answer.