Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

OnScrollListener

abstract class OnScrollListener
kotlin.Any
   ↳ androidx.recyclerview.widget.RecyclerView.OnScrollListener

An OnScrollListener can be added to a RecyclerView to receive messages when a scrolling event has occurred on that RecyclerView.

Summary

Public constructors

An OnScrollListener can be added to a RecyclerView to receive messages when a scrolling event has occurred on that RecyclerView.

Public methods

open Unit
onScrollStateChanged(@NonNull recyclerView: RecyclerView, newState: Int)

Callback method to be invoked when RecyclerView's scroll state changes.

open Unit
onScrolled(@NonNull recyclerView: RecyclerView, dx: Int, dy: Int)

Callback method to be invoked when the RecyclerView has been scrolled.

Public constructors

<init>

OnScrollListener()

An OnScrollListener can be added to a RecyclerView to receive messages when a scrolling event has occurred on that RecyclerView.

Public methods

onScrollStateChanged

open fun onScrollStateChanged(@NonNull recyclerView: RecyclerView, newState: Int): Unit

Callback method to be invoked when RecyclerView's scroll state changes.

Parameters
recyclerView RecyclerView: The RecyclerView whose scroll state has changed.
newState RecyclerView: The updated scroll state. One of SCROLL_STATE_IDLE, SCROLL_STATE_DRAGGING or SCROLL_STATE_SETTLING.

onScrolled

open fun onScrolled(@NonNull recyclerView: RecyclerView, dx: Int, dy: Int): Unit

Callback method to be invoked when the RecyclerView has been scrolled. This will be called after the scroll has completed.

This callback will also be called if visible item range changes after a layout calculation. In that case, dx and dy will be 0.

Parameters
recyclerView RecyclerView: The RecyclerView which scrolled.
dx RecyclerView: The amount of horizontal scroll.
dy RecyclerView: The amount of vertical scroll.