Skip to content

Most visited

Recently visited

navigation

RecyclerView.SmoothScroller

public static abstract class RecyclerView.SmoothScroller
extends Object

java.lang.Object
   ↳ android.support.v7.widget.RecyclerView.SmoothScroller
Known Direct Subclasses


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

See also:

Summary

Nested classes

class RecyclerView.SmoothScroller.Action

Holds information about a smooth scroll request by a RecyclerView.SmoothScroller

interface RecyclerView.SmoothScroller.ScrollVectorProvider

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

Public constructors

RecyclerView.SmoothScroller()

Public methods

View findViewByPosition(int position)
int getChildCount()
int getChildPosition(View view)
RecyclerView.LayoutManager getLayoutManager()
int getTargetPosition()

Returns the adapter position of the target item

void instantScrollToPosition(int position)

This method was deprecated in API level 22.2.1. Use jumpTo(int).

boolean isPendingInitialRun()

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

boolean isRunning()
void setTargetPosition(int targetPosition)

Protected methods

void normalize(PointF scrollVector)

Normalizes the vector.

void onChildAttachedToWindow(View child)
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.

abstract void onStart()

Called when smooth scroll is started.

abstract void onStop()

Called when smooth scroller is stopped.

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

Called when the target position is laid out.

final void stop()

Stops running the SmoothScroller in each animation callback.

Inherited methods

From class java.lang.Object

Public constructors

RecyclerView.SmoothScroller

added in version 22.0.0
RecyclerView.SmoothScroller ()

Public methods

findViewByPosition

added in version 22.0.0
View findViewByPosition (int position)

Parameters
position int

Returns
View

See also:

getChildCount

added in version 22.0.0
int getChildCount ()

Returns
int

See also:

getChildPosition

added in version 22.0.0
int getChildPosition (View view)

Parameters
view View

Returns
int

See also:

getLayoutManager

added in version 22.0.0
RecyclerView.LayoutManager getLayoutManager ()

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

getTargetPosition

added in version 22.0.0
int getTargetPosition ()

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 version 22.0.0
void instantScrollToPosition (int position)

This method was deprecated in API level 22.2.1.
Use jumpTo(int).

Parameters
position int

See also:

isPendingInitialRun

added in version 22.0.0
boolean isPendingInitialRun ()

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 version 22.0.0
boolean isRunning ()

Returns
boolean True if SmoothScroller is currently active

setTargetPosition

added in version 22.0.0
void setTargetPosition (int targetPosition)

Parameters
targetPosition int

Protected methods

normalize

added in version 22.0.0
void normalize (PointF scrollVector)

Normalizes the vector.

Parameters
scrollVector PointF: The vector that points to the target scroll position

onChildAttachedToWindow

added in version 22.0.0
void onChildAttachedToWindow (View child)

Parameters
child View

onSeekTargetStep

added in version 22.0.0
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 int: Last scroll amount horizontally

dy 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 version 22.0.0
void onStart ()

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

onStop

added in version 22.0.0
void onStop ()

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

See also:

onTargetFound

added in version 22.0.0
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 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 version 22.0.0
void stop ()

Stops running the SmoothScroller in each animation callback. Note that this does not cancel any existing RecyclerView.SmoothScroller.Action updated by onTargetFound(android.view.View, RecyclerView.State, SmoothScroller.Action) or onSeekTargetStep(int, int, RecyclerView.State, SmoothScroller.Action).

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)