RecyclerView.SmoothScroller


abstract class RecyclerView.SmoothScroller

Known direct subclasses
LinearSmoothScroller

RecyclerView.SmoothScroller implementation which uses a LinearInterpolator until the target position becomes a child of the RecyclerView and then uses a DecelerateInterpolator to slowly approach to target position.


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 startSmoothScroll.

Summary

Nested types

Holds information about a smooth scroll request by a SmoothScroller.

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 functions

PointF?

Compute the scroll vector for a given target position.

View!
Int
Int
RecyclerView.LayoutManager?
Int

Returns the adapter position of the target item

Unit

This function is deprecated.

Use jumpTo.

Boolean

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

Boolean
Unit
setTargetPosition(targetPosition: Int)

Protected functions

Unit
normalize(scrollVector: PointF)

Normalizes the vector.

Unit
abstract Unit
onSeekTargetStep(
    dx: @Px Int,
    dy: @Px Int,
    state: RecyclerView.State,
    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(
    targetView: View,
    state: RecyclerView.State,
    action: RecyclerView.SmoothScroller.Action
)

Called when the target position is laid out.

Unit

Stops running the SmoothScroller in each animation callback.

Public constructors

SmoothScroller

Added in 1.0.0
SmoothScroller()

Public functions

computeScrollVectorForPosition

Added in 1.0.0
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

Returns
PointF?

the scroll vector for a given target position

findViewByPosition

Added in 1.0.0
fun findViewByPosition(position: Int): View!

getChildCount

Added in 1.0.0
fun getChildCount(): Int
See also
getChildCount

getChildPosition

Added in 1.0.0
fun getChildPosition(view: View!): Int

getLayoutManager

Added in 1.0.0
fun getLayoutManager(): RecyclerView.LayoutManager?
Returns
RecyclerView.LayoutManager?

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

getTargetPosition

Added in 1.0.0
fun getTargetPosition(): Int

Returns the adapter position of the target item

Returns
Int

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

instantScrollToPosition

Added in 1.0.0
Deprecated in 1.0.0
fun instantScrollToPosition(position: Int): Unit
See also
scrollToPosition

isPendingInitialRun

Added in 1.0.0
fun isPendingInitialRun(): Boolean

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

Returns
Boolean

True if this SmoothScroller is waiting to start

isRunning

Added in 1.0.0
fun isRunning(): Boolean
Returns
Boolean

True if SmoothScroller is currently active

setTargetPosition

Added in 1.0.0
fun setTargetPosition(targetPosition: Int): Unit

Protected functions

normalize

Added in 1.0.0
protected fun normalize(scrollVector: PointF): Unit

Normalizes the vector.

Parameters
scrollVector: PointF

The vector that points to the target scroll position

onChildAttachedToWindow

Added in 1.0.0
protected fun onChildAttachedToWindow(child: View!): Unit

onSeekTargetStep

Added in 1.0.0
protected abstract fun onSeekTargetStep(
    dx: @Px Int,
    dy: @Px Int,
    state: RecyclerView.State,
    action: RecyclerView.SmoothScroller.Action
): Unit

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 Action to define the next scroll.

Parameters
dx: @Px Int

Last scroll amount horizontally

dy: @Px Int

Last scroll amount vertically

state: RecyclerView.State

Transient state of RecyclerView

action: RecyclerView.SmoothScroller.Action

If you want to trigger a new smooth scroll and cancel the previous one, update this object.

onStart

Added in 1.0.0
protected abstract fun onStart(): Unit

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

onStop

Added in 1.0.0
protected abstract fun onStop(): Unit

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

See also
stop

onTargetFound

Added in 1.0.0
protected abstract fun onTargetFound(
    targetView: View,
    state: RecyclerView.State,
    action: RecyclerView.SmoothScroller.Action
): Unit

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

Parameters
targetView: View

The view element which render the target position.

state: RecyclerView.State

Transient state of RecyclerView

action: RecyclerView.SmoothScroller.Action

Action instance that you should update to define final scroll action towards the targetView

stop

Added in 1.0.0
protected fun stop(): Unit

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