I am using Recyclerview with CardView. I am aware how to control speed on list view. But not for Recyclerview.
I searched a lot in found class name SmoothScroll. How to use that? I have no Idea! Right now Recyclerview by default scroll is fast.
UPDATE:
I Summarized Gil Answer with this
I just simplifying Answer how to use it to control smooth scroll.
Create Class
Adjust speed by Replacing 0.7 to your value.
Now use this class in your XML like this.
Read RecyclerView in Java like.
It's unclear what you mean when you say "
smoothScroll
". You could be referring to the automatic "smoothScrollToPosition
" which will automatically scroll to a specified position, you could be talking about manual scrolling and you could be talking about flinging. For the sake of prosperity, I will attempt to answer all of these issues now.1. Automatic smooth scrolling.
Inside your layout manager, you need to implement the
smoothScrollToPosition
method:In this example, I use a helper method named "calculateCurrentDistanceToPosition". This can be a bit tricky, since it involves keeping track of your current scroll position, and calculating the scroll position of a given y position. You can find an example of how to keep track of the recycler's scroll y here.
Calculating the scroll y of a given position is really dependent on what your recycler is displaying. Assuming all your items are the same height, you can calculate this by performing the following calculation:
Then, to calculate the distance you need to scroll, simply subtract the current scroll y with the target scroll y:
2. Slowing down manual scrolling.
Once again, you need to edit your layout manager, this time - the
scrollVerticallyBy
method:Edit: In the above method, I call "
getScrollState()
". This is a method ofRecyclerView
. In this implementation, my customLayoutManager
is a nested class of my customRecyclerView
. If this doesn't work for you, you can try to grab the scroll state via some interface pattern.3. Slow down the fling speed
Here you want to scale down the fling velocity. You will need to override the
fling
method inside your RecyclerView subclass:It's difficult for me to provide a more tailored solution, since you didn't post any of your code, or provide much information about your setup, but I hope this covers most bases and will help you find the best solution for you.
Simply implement smoothScrollToPosition() of your LinearLayoutManager: