Ihor Klimov
Ihor Klimov

Reputation: 953

Android RecyclerView Inertia

I've updated my RecyclerView version to 26.0.1 and I have pagination implemented with RecyclerView, so when I reach bottom of the list I see ProgressBar and load more data to display, then notify inserted indexes

So with new 26.0.1 RecyclerView version there's inertia saved from scrolling. So when I swipe down fast and reach bottom I see ProgressBar, but after new data inserted RecyclerView keeps scrolling down

I know that's it inertia because if I swipe slowly, it doesn't scroll down after new data being inserted

Question: how to disable this inertia swiping?

P.S. My RecyclerView is inside NestedScrollView

Upvotes: 2

Views: 761

Answers (2)

Aleksey Kislyakov
Aleksey Kislyakov

Reputation: 64

Sorry for late response, but I faced with the same issue. I had a NestedScrollView containing multiple items including RecyclerView. I noticed that when LOADING state is shown, everything scrolls without any inertia, but once I make recyclerView visible, inertia appears. That code helped me:

recyclerView.isNestedScrollingEnabled = false

It helped for androidX RecylerView widget.

Upvotes: 1

Josh H-D
Josh H-D

Reputation: 11

Ran into the same issue, a RecyclerView with infinite scrolling on API 26. Solved it by just adding this code to the overriden onScrolled event I was already using to load subsequent pages of data. I placed it after the super.onScrolled() call and before my infinite page loading trigger.

if (!recyclerView.canScrollVertically(1)) {
    recyclerView.stopScroll();
}

This detects whether the RecyclerView can no longer scroll downwards (1 for down, -1 for up), and uses the built-in method to halt scrolling.

Upvotes: 1

Related Questions