Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make RecyclerView scroll smoothly?

This is more like a generic question, but after lot of search and try I am not able to understand why this is so difficult to achieve. This is the closest answer I can find but still unable to implement.

To be specific I am using RecyclerView with GridLayoutManager. All I want is the grid layout to scroll smoothly (like default gallary app) ,nothing fancy, but the default implementation of grid layout manager scrolls the view in a 'jerky' manner. I tried to implement the method from above link but unsuccessfully.

I also tried to implement LinearSmoothScroller but I am not sure how to implement computeScrollVectorForPosition method. Google's documentation on computeScrollVectorForPosition literally has 0 words.

I found this 3 part tutorial, but it was of very little help. So, all I want to ask is: can there be some kind of template code which we can implement in LinearSmoothScroller or by extending RecyclerView.SmoothScroller and achieve smooth scrolling ? Even if the code depends on number of items and items per row in gridlayout, there has to be some method to do it easily. Am I missing something here ?

like image 856
rockfight Avatar asked Jul 06 '15 15:07

rockfight


People also ask

How make RecyclerView smooth scroll in android?

Also, if you are using a recycler view inside the scroll view, make sure to set nested scrolling to false. Show activity on this post. Use a library as said by other comments in here. Also make sure you do not have Recyclerviews nested within a Scrollview.

Why is RecyclerView lagging?

from my experience with recyclerview what i found the possible cause could be is the image size. beside that adding property ( setNestedScrollingEnabled(false); ) to the recyclerview and ( setHasStableIds ) to the adapter does help to make recyclerview work smoothly.


1 Answers

Add this wherever you have declared RecyclerView in your Activity or Fragment

RecyclerView mRecyclerview = (RecyclerView) findViewById(...); mRecyclerview.setNestedScrollingEnabled(false); 

setNestedScrollview(false) does the work for you.

like image 141
Ahmed Raza Avatar answered Sep 29 '22 04:09

Ahmed Raza