Previously, when I want to scroll a ListView
to a desired position, I will use
listView.setSelection(row);
The ListView
will be scrolled without any animation - Android List View set default position without animation
Now, I want to achieve the same effect on RecyclerView
. I try to perform
((LinearLayoutManager)recyclerView.getLayoutManager()).scrollToPositionWithOffset(row, 0);
However, there is scrolling animation, which I would like to avoid.
Is there any way I can perform programmatically scrolling, without animation?
This is the animation I meant - https://youtu.be/OKsUKwBLoks
Note, I had already tried the following ways. All of them do generate animation.
RecyclerView is the ViewGroup that contains the views corresponding to your data. It's a view itself, so you add RecyclerView into your layout the way you would add any other UI element. Each individual element in the list is defined by a view holder object.
What is RecyclerView in Android? The RecyclerView is a widget that is more flexible and advanced version of GridView and ListView. It is a container for displaying large datasets which can be scrolled efficiently by maintaining limited number of views.
I know I'm a little late with this answer but it may help someone else. Try following (at least I could not see any animation when using it):
//-- Immediately jump to the position in RecyclerView without delay or animation.
mRecyclerView.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
mRecyclerView.scrollToPosition(position)
mRecyclerView.viewTreeObserver.removeOnGlobalLayoutListener(this)
}
})
mRecyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mRecyclerView.scrollToPosition(position);
mRecyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With