Most visited

Recently visited

LinearSmoothScroller

public abstract class LinearSmoothScroller
extends RecyclerView.SmoothScroller

java.lang.Object
   ↳ android.support.v7.widget.RecyclerView.SmoothScroller
     ↳ android.support.v7.widget.LinearSmoothScroller


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

Summary

Constants

int SNAP_TO_ANY

Decides if the child should be snapped from start or end, depending on where it currently is in relation to its parent.

int SNAP_TO_END

Align child view's right or bottom with parent view's right or bottom

int SNAP_TO_START

Align child view's left or top with parent view's left or top

Fields

protected final DecelerateInterpolator mDecelerateInterpolator

protected int mInterimTargetDx

protected int mInterimTargetDy

protected final LinearInterpolator mLinearInterpolator

protected PointF mTargetVector

Public constructors

LinearSmoothScroller(Context context)

Public methods

int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference)

Helper method for calculateDxToMakeVisible(android.view.View, int) and calculateDyToMakeVisible(android.view.View, int)

int calculateDxToMakeVisible(View view, int snapPreference)

Calculates the horizontal scroll amount necessary to make the given view fully visible inside the RecyclerView.

int calculateDyToMakeVisible(View view, int snapPreference)

Calculates the vertical scroll amount necessary to make the given view fully visible inside the RecyclerView.

abstract PointF computeScrollVectorForPosition(int targetPosition)

Protected methods

float calculateSpeedPerPixel(DisplayMetrics displayMetrics)

Calculates the scroll speed.

int calculateTimeForDeceleration(int dx)

Calculates the time for deceleration so that transition from LinearInterpolator to DecelerateInterpolator looks smooth.

int calculateTimeForScrolling(int dx)

Calculates the time it should take to scroll the given distance (in pixels)

int getHorizontalSnapPreference()

When scrolling towards a child view, this method defines whether we should align the left or the right edge of the child with the parent RecyclerView.

int getVerticalSnapPreference()

When scrolling towards a child view, this method defines whether we should align the top or the bottom edge of the child with the parent RecyclerView.

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.

void onStart()

Called when smooth scroll is started.

void onStop()

Called when smooth scroller is stopped.

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

Called when the target position is laid out.

void updateActionForInterimTarget(RecyclerView.SmoothScroller.Action action)

When the target scroll position is not a child of the RecyclerView, this method calculates a direction vector towards that child and triggers a smooth scroll.

Inherited methods

From class android.support.v7.widget.RecyclerView.SmoothScroller
From class java.lang.Object

Constants

SNAP_TO_ANY

int SNAP_TO_ANY

Decides if the child should be snapped from start or end, depending on where it currently is in relation to its parent.

For instance, if the view is virtually on the left of RecyclerView, using SNAP_TO_ANY is the same as using SNAP_TO_START

See also:

Constant Value: 0 (0x00000000)

SNAP_TO_END

int SNAP_TO_END

Align child view's right or bottom with parent view's right or bottom

See also:

Constant Value: 1 (0x00000001)

SNAP_TO_START

int SNAP_TO_START

Align child view's left or top with parent view's left or top

See also:

Constant Value: -1 (0xffffffff)

Fields

mDecelerateInterpolator

DecelerateInterpolator mDecelerateInterpolator

mInterimTargetDx

int mInterimTargetDx

mInterimTargetDy

int mInterimTargetDy

mLinearInterpolator

LinearInterpolator mLinearInterpolator

mTargetVector

PointF mTargetVector

Public constructors

LinearSmoothScroller

LinearSmoothScroller (Context context)

Parameters
context Context

Public methods

calculateDtToFit

int calculateDtToFit (int viewStart, 
                int viewEnd, 
                int boxStart, 
                int boxEnd, 
                int snapPreference)

Helper method for calculateDxToMakeVisible(android.view.View, int) and calculateDyToMakeVisible(android.view.View, int)

Parameters
viewStart int
viewEnd int
boxStart int
boxEnd int
snapPreference int
Returns
int

calculateDxToMakeVisible

int calculateDxToMakeVisible (View view, 
                int snapPreference)

Calculates the horizontal scroll amount necessary to make the given view fully visible inside the RecyclerView.

Parameters
view View: The view which we want to make fully visible
snapPreference int: The edge which the view should snap to when entering the visible area. One of SNAP_TO_START, SNAP_TO_END or SNAP_TO_END
Returns
int The vertical scroll amount necessary to make the view visible with the given snap preference.

calculateDyToMakeVisible

int calculateDyToMakeVisible (View view, 
                int snapPreference)

Calculates the vertical scroll amount necessary to make the given view fully visible inside the RecyclerView.

Parameters
view View: The view which we want to make fully visible
snapPreference int: The edge which the view should snap to when entering the visible area. One of SNAP_TO_START, SNAP_TO_END or SNAP_TO_ANY.
Returns
int The vertical scroll amount necessary to make the view visible with the given snap preference.

computeScrollVectorForPosition

PointF computeScrollVectorForPosition (int targetPosition)

Parameters
targetPosition int
Returns
PointF

Protected methods

calculateSpeedPerPixel

float calculateSpeedPerPixel (DisplayMetrics displayMetrics)

Calculates the scroll speed.

Parameters
displayMetrics DisplayMetrics: DisplayMetrics to be used for real dimension calculations
Returns
float The time (in ms) it should take for each pixel. For instance, if returned value is 2 ms, it means scrolling 1000 pixels with LinearInterpolation should take 2 seconds.

calculateTimeForDeceleration

int calculateTimeForDeceleration (int dx)

Calculates the time for deceleration so that transition from LinearInterpolator to DecelerateInterpolator looks smooth.

Parameters
dx int: Distance to scroll
Returns
int Time for DecelerateInterpolator to smoothly traverse the distance when transitioning from LinearInterpolation

calculateTimeForScrolling

int calculateTimeForScrolling (int dx)

Calculates the time it should take to scroll the given distance (in pixels)

Parameters
dx int: Distance in pixels that we want to scroll
Returns
int Time in milliseconds

See also:

getHorizontalSnapPreference

int getHorizontalSnapPreference ()

When scrolling towards a child view, this method defines whether we should align the left or the right edge of the child with the parent RecyclerView.

Returns
int SNAP_TO_START, SNAP_TO_END or SNAP_TO_ANY; depending on the current target vector

See also:

getVerticalSnapPreference

int getVerticalSnapPreference ()

When scrolling towards a child view, this method defines whether we should align the top or the bottom edge of the child with the parent RecyclerView.

Returns
int SNAP_TO_START, SNAP_TO_END or SNAP_TO_ANY; depending on the current target vector

See also:

onSeekTargetStep

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 verticaully
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

void onStart ()

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

onStop

void onStop ()

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

onTargetFound

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

updateActionForInterimTarget

void updateActionForInterimTarget (RecyclerView.SmoothScroller.Action action)

When the target scroll position is not a child of the RecyclerView, this method calculates a direction vector towards that child and triggers a smooth scroll.

Parameters
action RecyclerView.SmoothScroller.Action

See also:

Hooray!