Android 12 Developer Preview is here! Try it out, and give us your feedback!

SmoothScroller

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

Base class for smooth scrolling. Handles basic tracking of the target view position and provides methods to trigger a programmatic scroll.

An instance of SmoothScroller is only intended to be used once. You should create a new instance for each call to LayoutManager#startSmoothScroll(SmoothScroller).

Summary

Nested classes
open

Holds information about a smooth scroll request by a SmoothScroller.

abstract

An interface which is optionally implemented by custom RecyclerView.LayoutManager to provide a hint to a SmoothScroller about the location of the target position.

Public constructors

Public methods
open PointF?

Compute the scroll vector for a given target position.

open View!

open Int

open Int

open RecyclerView.LayoutManager?

open Int

Returns the adapter position of the target item

open Unit

open Boolean

Returns true if SmoothScroller has been started but has not received the first animation callback yet.

open Boolean

open Unit
setTargetPosition(targetPosition: Int)

Protected methods
open Unit
normalize(@NonNull scrollVector: PointF)

Normalizes the vector.

open Unit

abstract Unit
onSeekTargetStep(@Px dx: Int, @Px dy: Int, @NonNull state: RecyclerView.State, @NonNull action: RecyclerView.SmoothScroller.Action)

RecyclerView will call this method each time it scrolls until it can find the target position in the layout.

abstract Unit

Called when smooth scroll is started.

abstract Unit

Called when smooth scroller is stopped.

abstract Unit
onTargetFound(@NonNull targetView: View, @NonNull state: RecyclerView.State, @NonNull action: RecyclerView.SmoothScroller.Action)

Called when the target position is laid out.

Unit

Stops running the SmoothScroller in each animation callback.

Public constructors

<init>

SmoothScroller()

Public methods

computeScrollVectorForPosition

@Nullable open fun computeScrollVectorForPosition(targetPosition: Int): PointF?

Compute the scroll vector for a given target position.

This method can return null if the layout manager cannot calculate a scroll vector for the given position (e.g. it has no current scroll position).

Parameters
targetPosition Int: the position to which the scroller is scrolling
Return
PointF? the scroll vector for a given target position

findViewByPosition

open fun findViewByPosition(position: Int): View!

getChildCount

open fun getChildCount(): Int

getChildPosition

open fun getChildPosition(view: View!):