belongs to Maven artifact androidx.car:car:1.0.0-alpha4

PagedSmoothScroller

public final class PagedSmoothScroller
extends LinearSmoothScroller

java.lang.Object
   ↳ androidx.recyclerview.widget.RecyclerView.SmoothScroller
     ↳ androidx.recyclerview.widget.LinearSmoothScroller
       ↳ androidx.car.widget.PagedSmoothScroller


Custom LinearSmoothScroller that has:

  • Custom control over the speed of scrolls.
  • Scrolling that snaps to start of a child view.

Summary

Inherited constants

Inherited fields

Public constructors

PagedSmoothScroller(Context context)

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 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 onTargetFound(View targetView, RecyclerView.State state, RecyclerView.SmoothScroller.Action action)

Called when the target position is laid out.

Inherited methods

Public constructors

PagedSmoothScroller

public PagedSmoothScroller (Context context)

Parameters
context Context

Protected methods

calculateSpeedPerPixel

protected 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

protected 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

getVerticalSnapPreference

protected 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

onTargetFound

protected 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