How do I stay in the scroll position in the RecyclerView after adding items to its first index?

I am using a RecyclerView in my app, adding more items to RecyclerView

after its last item makes the RecyclerView scroll to stay in place, but when I add items before the first item, the scroll position moves up the first item is added. How can I keep my scroll position after adding new items to my first index?

+3


source to share


1 answer


RecyclerView has a method yourRecyclerView.scrollToPosition(int_position_value);

, you just need to pass this method to your position and it will scroll down or up depending on the position. Now you need to do the following: after adding the element / elements, calculate the position to which you want to scroll and pass it to this method.



0


source







All Articles