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实现,它使用 LinearInterpolator直到目标位置成为RecyclerView的子项,然后使用 DecelerateInterpolator缓慢接近目标位置。

Summary

Constants

int SNAP_TO_ANY

决定是否应该从开始或结束时扣除儿童,具体取决于当前与父母相关的位置。

int SNAP_TO_END

将子视图的右侧或底部与父视图的右侧或底部对齐

int SNAP_TO_START

将子视图的左侧或顶部与父视图的左侧或顶部对齐

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方法 calculateDxToMakeVisible(android.view.View, int)calculateDyToMakeVisible(android.view.View, int)

int calculateDxToMakeVisible(View view, int snapPreference)

计算使RecyclerView内的给定视图完全可见的必要水平滚动量。

int calculateDyToMakeVisible(View view, int snapPreference)

计算使RecyclerView内的给定视图完全可见的垂直滚动量。

abstract PointF computeScrollVectorForPosition(int targetPosition)

Protected methods

float calculateSpeedPerPixel(DisplayMetrics displayMetrics)

计算滚动速度。

int calculateTimeForDeceleration(int dx)

计算减速时间,以便从LinearInterpolator到DecelerateInterpolator的转换看起来平滑。

int calculateTimeForScrolling(int dx)

计算滚动给定距离所需的时间(以像素为单位)

int getHorizontalSnapPreference()

当向子视图滚动时,此方法定义我们是应该将子对象的左边还是右边与父级RecyclerView对齐。

int getVerticalSnapPreference()

当滚动到一个子视图时,这个方法定义我们是否应该将子对象的顶部或底部边缘与父级RecyclerView对齐。

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

RecyclerView会在每次滚动时调用此方法,直到它可以在布局中找到目标位置。

void onStart()

当平滑滚动开始时调用。

void onStop()

当平滑滚轮停止时调用。

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

目标位置布局时调用。

void updateActionForInterimTarget(RecyclerView.SmoothScroller.Action action)

当目标滚动位置不是RecyclerView的子项时,此方法计算朝向该子项的方向矢量并触发平滑滚动。

Inherited methods

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

Constants

SNAP_TO_ANY

int SNAP_TO_ANY

决定是否应该从开始或结束时扣除儿童,具体取决于当前与父母相关的位置。

例如,如果视图实际上位于RecyclerView左侧,则使用 SNAP_TO_ANY与使用 SNAP_TO_START

也可以看看:

常量值:0(0x00000000)

SNAP_TO_END

int SNAP_TO_END

将子视图的右侧或底部与父视图的右侧或底部对齐

也可以看看:

常数值:1(0x00000001)

SNAP_TO_START

int SNAP_TO_START

将子视图的左侧或顶部与父视图的左侧或顶部对齐

也可以看看:

常量值:-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)

助手方法 calculateDxToMakeVisible(android.view.View, int)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)

计算使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)

计算使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)

计算滚动速度。

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)

计算减速时间,以便从LinearInterpolator到DecelerateInterpolator的转换看起来平滑。

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)

计算滚动给定距离所需的时间(以像素为单位)

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

也可以看看:

getHorizontalSnapPreference

int getHorizontalSnapPreference ()

当向子视图滚动时,此方法定义我们是应该将子对象的左边还是右边与父级RecyclerView对齐。

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

也可以看看:

getVerticalSnapPreference

int getVerticalSnapPreference ()

当滚动到一个子视图时,这个方法定义我们是否应该将子对象的顶部或底部边缘与父级RecyclerView对齐。

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

也可以看看:

onSeekTargetStep

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

RecyclerView会在每次滚动时调用此方法,直到它可以在布局中找到目标位置。

SmoothScroller应该检查dx,dy,如果应该更改滚动,请更新提供的 RecyclerView.SmoothScroller.Action以定义下一个滚动。

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 ()

当平滑滚动开始时调用。 这可能是设置的好时机。

onStop

void onStop ()

当平滑滚轮停止时调用。 这是清理你的国家等的好地方。

onTargetFound

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

目标位置布局时调用。 这是SmoothScroller将接收的最后一次回调,它应该更新提供的RecyclerView.SmoothScroller.Action以定义滚动细节到目标视图。

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)

当目标滚动位置不是RecyclerView的子项时,此方法计算朝向该子项的方向矢量并触发平滑滚动。

Parameters
action RecyclerView.SmoothScroller.Action

也可以看看:

Hooray!