public abstract class

RecyclerView.SmoothScroller

extends java.lang.Object

 java.lang.Object

↳androidx.recyclerview.widget.RecyclerView.SmoothScroller

Subclasses:

LinearSmoothScroller

Overview

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 RecyclerView.LayoutManager.

Summary

Constructors
publicSmoothScroller()

Methods
public PointFcomputeScrollVectorForPosition(int targetPosition)

Compute the scroll vector for a given target position.

public ViewfindViewByPosition(int position)

public intgetChildCount()

public intgetChildPosition(View view)

public RecyclerView.LayoutManagergetLayoutManager()

public intgetTargetPosition()

Returns the adapter position of the target item

public voidinstantScrollToPosition(int position)

public booleanisPendingInitialRun()

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

public booleanisRunning()

protected voidnormalize(PointF scrollVector)

Normalizes the vector.

protected voidonChildAttachedToWindow(View child)

protected abstract voidonSeekTargetStep(int dx, int dy, RecyclerView.State state, RecyclerView.SmoothScroller.Action action)

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

protected abstract voidonStart()

Called when smooth scroll is started.

protected abstract voidonStop()

Called when smooth scroller is stopped.

protected abstract voidonTargetFound(View targetView, RecyclerView.State state, RecyclerView.SmoothScroller.Action action)

Called when the target position is laid out.

public voidsetTargetPosition(int targetPosition)

protected final voidstop()

Stops running the SmoothScroller in each animation callback.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public SmoothScroller()

Methods

public void setTargetPosition(int targetPosition)

public PointF computeScrollVectorForPosition(int targetPosition)

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: the position to which the scroller is scrolling

Returns:

the scroll vector for a given target position

public RecyclerView.LayoutManager getLayoutManager()

Returns:

The LayoutManager to which this SmoothScroller is attached. Will return null after the SmoothScroller is stopped.

protected final void stop()

Stops running the SmoothScroller in each animation callback. Note that this does not cancel any existing RecyclerView.SmoothScroller.Action updated by RecyclerView.SmoothScroller or RecyclerView.SmoothScroller.

public boolean isPendingInitialRun()

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

Returns:

True if this SmoothScroller is waiting to start

public boolean isRunning()

Returns:

True if SmoothScroller is currently active

public int getTargetPosition()

Returns the adapter position of the target item

Returns:

Adapter position of the target item or RecyclerView.NO_POSITION if no target view is set.

public int getChildPosition(View view)

See also: RecyclerView

public int getChildCount()

See also: RecyclerView.LayoutManager.getChildCount()

public View findViewByPosition(int position)

See also: RecyclerView.LayoutManager.findViewByPosition(int)

public void instantScrollToPosition(int position)

Deprecated: Use RecyclerView.SmoothScroller.Action.jumpTo(int).

See also: RecyclerView.scrollToPosition(int)

protected void onChildAttachedToWindow(View child)

protected void normalize(PointF scrollVector)

Normalizes the vector.

Parameters:

scrollVector: The vector that points to the target scroll position

protected abstract void onStart()

Called when smooth scroll is started. This might be a good time to do setup.

protected abstract void onStop()

Called when smooth scroller is stopped. This is a good place to cleanup your state etc.

See also: RecyclerView.SmoothScroller.stop()

protected abstract void onSeekTargetStep(int dx, int dy, RecyclerView.State state, RecyclerView.SmoothScroller.Action action)

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

SmoothScroller should check dx, dy and if scroll should be changed, update the provided RecyclerView.SmoothScroller.Action to define the next scroll.

Parameters:

dx: Last scroll amount horizontally
dy: Last scroll amount vertically
state: Transient state of RecyclerView
action: If you want to trigger a new smooth scroll and cancel the previous one, update this object.

protected abstract void onTargetFound(View targetView, RecyclerView.State state, RecyclerView.SmoothScroller.Action action)

Called when the target position is laid out. This is the last callback SmoothScroller will receive and it should update the provided RecyclerView.SmoothScroller.Action to define the scroll details towards the target view.

Parameters:

targetView: The view element which render the target position.
state: Transient state of RecyclerView
action: Action instance that you should update to define final scroll action towards the targetView