Most visited

Recently visited

ItemTouchHelper.Callback

public static abstract class ItemTouchHelper.Callback
extends Object

java.lang.Object
   ↳ android.support.v7.widget.helper.ItemTouchHelper.Callback
Known Direct Subclasses


这个类是ItemTouchHelper和你的应用程序之间的契约。 它允许您控制每个ViewHolder启用哪些触摸行为,并在用户执行这些操作时接收回调。

要控制用户可以在每个视图上执行哪些操作,应该覆盖getMovementFlags(RecyclerView, ViewHolder)并返回适当的方向标记集。 LEFTRIGHTSTARTENDUPDOWN )。 您可以使用makeMovementFlags(int, int)轻松构建它。 或者,您可以使用ItemTouchHelper.SimpleCallback

如果用户拖动一个项目,ItemTouchHelper将会调用onMove(recyclerView, dragged, target) 收到此回调后,您应该将该项目从旧位置( dragged.getAdapterPosition() )移至适配器中的新位置( target.getAdapterPosition() ),并且还请拨打notifyItemMoved(int, int) 要控制View的放置位置,可以覆盖canDropOver(RecyclerView, ViewHolder, ViewHolder) 当拖动视图与多个其他视图重叠时,回调会选择最近的视图,拖动视图可能会更改位置。 尽管此方法适用于许多用例,但如果您有自定义LayoutManager,则可以覆盖chooseDropTarget(ViewHolder, java.util.List, int, int)以选择自定义放置目标。

当一个视图被刷过时,ItemTouchHelper为它动画,直到它超出界限,然后调用onSwiped(ViewHolder, int) 此时,您应该更新您的适配器(例如移除该项目)并调用相关的适配器#通知事件。

Summary

Constants

int DEFAULT_DRAG_ANIMATION_DURATION

int DEFAULT_SWIPE_ANIMATION_DURATION

Public constructors

ItemTouchHelper.Callback()

Public methods

boolean canDropOver(RecyclerView recyclerView, RecyclerView.ViewHolder current, RecyclerView.ViewHolder target)

如果当前ViewHolder可以放在目标ViewHolder上,则返回true。

RecyclerView.ViewHolder chooseDropTarget(RecyclerView.ViewHolder selected, List<RecyclerView.ViewHolder> dropTargets, int curX, int curY)

由ItemTouchHelper调用以从ViewHolders列表中选择拖放视图下的放置目标。

void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder)

当用户与元素交互结束并且它也完成其动画时,由ItemTouchHelper调用。

int convertToAbsoluteDirection(int flags, int layoutDirection)

将给定的一组标志转换为绝对方向,这意味着 STARTEND将根据布局方向由 LEFTRIGHT取代。

static int convertToRelativeDirection(int flags, int layoutDirection)

将布局方向考虑在内,用相对版本替换移动方向。

long getAnimationDuration(RecyclerView recyclerView, int animationType, float animateDx, float animateDy)

用户操作在ViewHolder上完成时,由ItemTouchHelper调用,现在视图将动画化到其最终位置。

int getBoundingBoxMargin()

在拖动视图下查找视图时,默认情况下,ItemTouchHelper将搜索与拖动视图重叠的视图。

static ItemTouchUIUtil getDefaultUIUtil()

返回 ItemTouchUIUtil所使用由 ItemTouchHelper.Callback响应于用户交互类有关视图的视觉变化。

float getMoveThreshold(RecyclerView.ViewHolder viewHolder)

返回用户应该移动视图的分数,以便在拖动视图时考虑。

abstract int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder)

应该返回一个组合标志,该标志定义每个状态下的启用移动方向(空闲,滑动,拖动)。

float getSwipeEscapeVelocity(float defaultValue)

定义将被用户视为滑动操作的最小速度。

float getSwipeThreshold(RecyclerView.ViewHolder viewHolder)

返回用户应将视图移动到视图中的部分。

float getSwipeVelocityThreshold(float defaultValue)

定义ItemTouchHelper为指针移动而计算的最大速度。

int interpolateOutOfBoundsScroll(RecyclerView recyclerView, int viewSize, int viewSizeOutOfBounds, int totalSize, long msSinceStartScroll)

当用户将视图拖出边界时,由ItemTouchHelper调用。

boolean isItemViewSwipeEnabled()

如果指针在视图上滑动,则返回ItemTouchHelper是否应该开始滑动操作。

boolean isLongPressDragEnabled()

如果长时间按下某个项目,则返回ItemTouchHelper是否应该开始拖放操作。

static int makeFlag(int actionState, int directions)

将给定的方向标志移动到给定动作状态的偏移量。

static int makeMovementFlags(int dragFlags, int swipeFlags)

便捷的方法来创建移动标志。

void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive)

由RecyclerView的onDraw回调中的ItemTouchHelper调用。

void onChildDrawOver(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive)

由RecyclerView的onDraw回调中的ItemTouchHelper调用。

abstract boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target)

当ItemTouchHelper想要将拖动的物品从旧位置移动到新位置时调用。

void onMoved(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, int fromPos, RecyclerView.ViewHolder target, int toPos, int x, int y)

onMove(RecyclerView, ViewHolder, ViewHolder)返回true时调用。

void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState)

当由ItemTouchHelper滑动或拖动的ViewHolder更改时调用。

abstract void onSwiped(RecyclerView.ViewHolder viewHolder, int direction)

当用户刷新ViewHolder时调用。

Inherited methods

From class java.lang.Object

Constants

DEFAULT_DRAG_ANIMATION_DURATION

int DEFAULT_DRAG_ANIMATION_DURATION

常量值:200(0x000000c8)

DEFAULT_SWIPE_ANIMATION_DURATION

int DEFAULT_SWIPE_ANIMATION_DURATION

常量值:250(0x000000fa)

Public constructors

ItemTouchHelper.Callback

ItemTouchHelper.Callback ()

Public methods

canDropOver

boolean canDropOver (RecyclerView recyclerView, 
                RecyclerView.ViewHolder current, 
                RecyclerView.ViewHolder target)

如果当前ViewHolder可以放在目标ViewHolder上,则返回true。

选择拖放视图的拖放目标时使用此方法。 通过边界检查或通过此方法消除视图后,所得视图集将传递到chooseDropTarget(ViewHolder, java.util.List, int, int)

默认实现返回true。

Parameters
recyclerView RecyclerView: The RecyclerView to which ItemTouchHelper is attached to.
current RecyclerView.ViewHolder: The ViewHolder that user is dragging.
target RecyclerView.ViewHolder: The ViewHolder which is below the dragged ViewHolder.
Returns
boolean True if the dragged ViewHolder can be replaced with the target ViewHolder, false otherwise.

chooseDropTarget

RecyclerView.ViewHolder chooseDropTarget (RecyclerView.ViewHolder selected, 
                List<RecyclerView.ViewHolder> dropTargets, 
                int curX, 
                int curY)

由ItemTouchHelper调用以从ViewHolders列表中选择拖放视图下的放置目标。

默认实现过滤拖动项目在拖动方向上已经改变位置的视图。 例如,如果视图被向上拖动,则比较拖动开始前后两个视图的view.getTop() 如果该值不同,则目标视图将通过过滤器。

在通过测试的这些视图中,选择了最靠近拖动视图的视图。

每次用户移动视图时,都会在主线程上调用此方法。 如果你想覆盖它,确保它不做任何昂贵的操作。

Parameters
selected RecyclerView.ViewHolder: The ViewHolder being dragged by the user.
dropTargets List: The list of ViewHolder that are under the dragged View and candidate as a drop.
curX int: The updated left value of the dragged View after drag translations are applied. This value does not include margins added by RecyclerView.ItemDecorations.
curY int: The updated top value of the dragged View after drag translations are applied. This value does not include margins added by RecyclerView.ItemDecorations.
Returns
RecyclerView.ViewHolder A ViewHolder to whose position the dragged ViewHolder should be moved to.

clearView

void clearView (RecyclerView recyclerView, 
                RecyclerView.ViewHolder viewHolder)

当用户与元素交互结束并且它也完成其动画时,由ItemTouchHelper调用。

这是为了清除这是在完成全部查看变化的好地方 onSelectedChanged(RecyclerView.ViewHolder, int)onChildDraw(Canvas, RecyclerView, ViewHolder, float, float, int, boolean)或者 onChildDrawOver(Canvas, RecyclerView, ViewHolder, float, float, int, boolean)

Parameters
recyclerView RecyclerView: The RecyclerView which is controlled by the ItemTouchHelper.
viewHolder RecyclerView.ViewHolder: The View that was interacted by the user.

convertToAbsoluteDirection

int convertToAbsoluteDirection (int flags, 
                int layoutDirection)

将给定的一组标志转换为绝对方向,这意味着 STARTEND被替换为 LEFTRIGHT具体取决于布局方向。

Parameters
flags int: The flag value that include any number of movement flags.
layoutDirection int: The layout direction of the RecyclerView.
Returns
int Updated flags which includes only absolute direction values.

convertToRelativeDirection

int convertToRelativeDirection (int flags, 
                int layoutDirection)

将布局方向考虑在内,用相对版本替换移动方向。

Parameters
flags int: The flag value that include any number of movement flags.
layoutDirection int: The layout direction of the View. Can be obtained from getLayoutDirection(android.view.View).
Returns
int Updated flags which uses relative flags (START, END) instead of LEFT, RIGHT.

也可以看看:

getAnimationDuration

long getAnimationDuration (RecyclerView recyclerView, 
                int animationType, 
                float animateDx, 
                float animateDy)

用户操作在ViewHolder上完成时,由ItemTouchHelper调用,现在视图将动画化到其最终位置。

默认实现使用ItemAnimator的持续时间值。 如果animationTypeANIMATION_TYPE_DRAG ,则返回getMoveDuration() ,否则返回getRemoveDuration() 如果RecyclerView没有附加任何RecyclerView.ItemAnimator ,则此方法根据动画类型返回DEFAULT_DRAG_ANIMATION_DURATIONDEFAULT_SWIPE_ANIMATION_DURATION

Parameters
recyclerView RecyclerView: The RecyclerView to which the ItemTouchHelper is attached to.
animationType int: The type of animation. Is one of ANIMATION_TYPE_DRAG, ANIMATION_TYPE_SWIPE_CANCEL or ANIMATION_TYPE_SWIPE_SUCCESS.
animateDx float: The horizontal distance that the animation will offset
animateDy float: The vertical distance that the animation will offset
Returns
long The duration for the animation

getBoundingBoxMargin

int getBoundingBoxMargin ()

在拖动视图下查找视图时,默认情况下,ItemTouchHelper将搜索与拖动视图重叠的视图。 通过重写此方法,可以扩展或缩小搜索框。

Returns
int The extra margin to be added to the hit box of the dragged View.

getDefaultUIUtil

ItemTouchUIUtil getDefaultUIUtil ()

返回ItemTouchUIUtil所使用由ItemTouchHelper.Callback响应于用户交互类有关视图的视觉变化。 ItemTouchUIUtil针对不同平台版本有不同的实现。

默认情况下, ItemTouchHelper.CallbackitemView上应用这些更改。

例如,如果您有一个用户只需在用户在视图上滑动时移动文本的用例,则可以执行以下操作:

     public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder){
         getDefaultUIUtil().clearView(((ItemTouchViewHolder) viewHolder).textView);
     }
     public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
         if (viewHolder != null){
             getDefaultUIUtil().onSelected(((ItemTouchViewHolder) viewHolder).textView);
         }
     }
     public void onChildDraw(Canvas c, RecyclerView recyclerView,
             RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState,
             boolean isCurrentlyActive) {
         getDefaultUIUtil().onDraw(c, recyclerView,
                 ((ItemTouchViewHolder) viewHolder).textView, dX, dY,
                 actionState, isCurrentlyActive);
         return true;
     }
     public void onChildDrawOver(Canvas c, RecyclerView recyclerView,
             RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState,
             boolean isCurrentlyActive) {
         getDefaultUIUtil().onDrawOver(c, recyclerView,
                 ((ItemTouchViewHolder) viewHolder).textView, dX, dY,
                 actionState, isCurrentlyActive);
         return true;
     }
 

Returns
ItemTouchUIUtil The ItemTouchUIUtil instance that is used by the ItemTouchHelper.Callback

getMoveThreshold

float getMoveThreshold (RecyclerView.ViewHolder viewHolder)

返回用户应该移动视图的分数,以便在拖动视图时考虑。 在视图移动这一数量后,ItemTouchHelper开始检查下面的Views以查看可能的下降。

Parameters
viewHolder RecyclerView.ViewHolder: The ViewHolder that is being dragged.
Returns
float A float value that denotes the fraction of the View size. Default value is .5f .

getMovementFlags

int getMovementFlags (RecyclerView recyclerView, 
                RecyclerView.ViewHolder viewHolder)

应该返回一个组合标志,该标志定义每个状态下的启用移动方向(空闲,滑动,拖动)。

您可以使用 makeMovementFlags(int, int)makeFlag(int, int)而不是手动组合此标志。

该标志由3组8位组成,其中前8位用于IDLE状态,后8位用于SWIPE状态,第3位8位用于DRAG状态。 每个8位段可以通过简单的OR'ing方向标志来构造,在ItemTouchHelper定义。

例如,如果您希望允许向左和向右滑动但只允许通过向右滑动来开始滑动,则可以返回:

      makeFlag(ACTION_STATE_IDLE, RIGHT) | makeFlag(ACTION_STATE_SWIPE, LEFT | RIGHT);
 
This means, allow right movement while IDLE and allow right and left movement while swiping.

Parameters
recyclerView RecyclerView: The RecyclerView to which ItemTouchHelper is attached.
viewHolder RecyclerView.ViewHolder: The ViewHolder for which the movement information is necessary.
Returns
int flags specifying which movements are allowed on this ViewHolder.

也可以看看:

getSwipeEscapeVelocity

float getSwipeEscapeVelocity (float defaultValue)

定义将被用户视为滑动操作的最小速度。

您可以增加此值,以便更轻松地滑动或减小它以使其更容易。 请记住,ItemTouchHelper还检查垂直速度,并确保当前的方向速度大于垂直速度。 否则,用户的移动是不明确的。 您可以通过覆盖getSwipeVelocityThreshold(float)来更改阈值。

速度是以像素每秒计算的。

默认框架值作为参数传递,以便您可以使用乘数对其进行修改。

Parameters
defaultValue float: The default value (in pixels per second) used by the ItemTouchHelper.
Returns
float The minimum swipe velocity. The default implementation returns the defaultValue parameter.

也可以看看:

getSwipeThreshold

float getSwipeThreshold (RecyclerView.ViewHolder viewHolder)

返回用户应将视图移动到视图中的部分。 该分数是根据RecyclerView的界限计算的。

默认值为.5f,也就是说,要扫描View,用户必须将View至少移动RecyclerView的宽度或高度的一半,具体取决于滑动方向。

Parameters
viewHolder RecyclerView.ViewHolder: The ViewHolder that is being dragged.
Returns
float A float value that denotes the fraction of the View size. Default value is .5f .

getSwipeVelocityThreshold

float getSwipeVelocityThreshold (float defaultValue)

定义ItemTouchHelper为指针移动而计算的最大速度。

要将移动看作滑动,ItemTouchHelper要求它大于垂直移动。 如果两个方向都达到最大阈值,则它们都不会被视为轻扫,因为这通常表示用户试图滚动然后滑动。

速度是以像素每秒计算的。

您可以通过更改此方法来自定义此行为。 如果增加该值,用户将更容易对角滑动,并且如果减小该值,用户需要做出相当笔直的手指移动来触发滑动。

Parameters
defaultValue float: The default value(in pixels per second) used by the ItemTouchHelper.
Returns
float The velocity cap for pointer movements. The default implementation returns the defaultValue parameter.

也可以看看:

interpolateOutOfBoundsScroll

int interpolateOutOfBoundsScroll (RecyclerView recyclerView, 
                int viewSize, 
                int viewSizeOutOfBounds, 
                int totalSize, 
                long msSinceStartScroll)

当用户将视图拖出边界时,由ItemTouchHelper调用。

您可以重写此方法来决定RecyclerView应该滚动多少以响应此操作。 默认实现根据View的数量越界和在那里花费的时间来计算一个值。 越长的用户保持视图越界,列表将滚动得越快。 同样,视图的大部分越界,RecyclerView将滚动得越快。

Parameters
recyclerView RecyclerView: The RecyclerView instance to which ItemTouchHelper is attached to.
viewSize int: The total size of the View in scroll direction, excluding item decorations.
viewSizeOutOfBounds int: The total size of the View that is out of bounds. This value is negative if the View is dragged towards left or top edge.
totalSize int: The total size of RecyclerView in the scroll direction.
msSinceStartScroll long: The time passed since View is kept out of bounds.
Returns
int The amount that RecyclerView should scroll. Keep in mind that this value will be passed to scrollBy(int, int) method.

isItemViewSwipeEnabled

boolean isItemViewSwipeEnabled ()

如果指针在视图上滑动,则返回ItemTouchHelper是否应该开始滑动操作。

默认值返回true,但如果您想要使用 startSwipe(ViewHolder)开始在自定义视图触摸上滑动,则可能需要禁用此 startSwipe(ViewHolder)

Returns
boolean True if ItemTouchHelper should start swiping an item when user swipes a pointer over the View, false otherwise. Default value is true.

也可以看看:

isLongPressDragEnabled

boolean isLongPressDragEnabled ()

如果长时间按下某个项目,则返回ItemTouchHelper是否应该开始拖放操作。

默认值返回true,但如果您想要使用 startDrag(ViewHolder)开始拖动自定义视图触摸,则可能需要禁用该 startDrag(ViewHolder)

Returns
boolean True if ItemTouchHelper should start dragging an item when it is long pressed, false otherwise. Default value is true.

也可以看看:

makeFlag

int makeFlag (int actionState, 
                int directions)

将给定的方向标志移动到给定动作状态的偏移量。

Parameters
actionState int: The action state you want to get flags in. Should be one of ACTION_STATE_IDLE, ACTION_STATE_SWIPE or ACTION_STATE_DRAG.
directions int: The direction flags. Can be composed from UP, DOWN, RIGHT, LEFT START and END.
Returns
int And integer that represents the given directions in the provided actionState.

makeMovementFlags

int makeMovementFlags (int dragFlags, 
                int swipeFlags)

便捷的方法来创建移动标志。

例如,如果您想让项目垂直拖放并向左滑动即可解除对象,则可以使用以下方法调用此方法: makeMovementFlags(UP | DOWN, LEFT);

Parameters
dragFlags int: The directions in which the item can be dragged.
swipeFlags int: The directions in which the item can be swiped.
Returns
int Returns an integer composed of the given drag and swipe flags.

onChildDraw

void onChildDraw (Canvas c, 
                RecyclerView recyclerView, 
                RecyclerView.ViewHolder viewHolder, 
                float dX, 
                float dY, 
                int actionState, 
                boolean isCurrentlyActive)

由RecyclerView的onDraw回调中的ItemTouchHelper调用。

如果您想自定义视图对用户交互的响应方式,那么这是一个很好的重写位置。

默认实现由给定翻译孩子dXdY ItemTouchHelper还负责在其他孩子被拖动后绘制孩子。 这是通过使用子重新排序机制来完成的。 在L之前的平台上,这是通过getChildDrawingOrder(int, int)实现的,在L和之后,它将View的高程值更改为大于其他所有孩子。)

Parameters
c Canvas: The canvas which RecyclerView is drawing its children
recyclerView RecyclerView: The RecyclerView to which ItemTouchHelper is attached to
viewHolder RecyclerView.ViewHolder: The ViewHolder which is being interacted by the User or it was interacted and simply animating to its original position
dX float: The amount of horizontal displacement caused by user's action
dY float: The amount of vertical displacement caused by user's action
actionState int: The type of interaction on the View. Is either ACTION_STATE_DRAG or ACTION_STATE_SWIPE.
isCurrentlyActive boolean: True if this view is currently being controlled by the user or false it is simply animating back to its original state.

也可以看看:

onChildDrawOver

void onChildDrawOver (Canvas c, 
                RecyclerView recyclerView, 
                RecyclerView.ViewHolder viewHolder, 
                float dX, 
                float dY, 
                int actionState, 
                boolean isCurrentlyActive)

由RecyclerView的onDraw回调中的ItemTouchHelper调用。

如果您想自定义视图对用户交互的响应方式,那么这是一个很好的重写位置。

默认实现由给定翻译孩子dXdY ItemTouchHelper还负责在其他孩子被拖动后绘制孩子。 这是通过使用子重新排序机制来完成的。 在L之前的平台上,这是通过getChildDrawingOrder(int, int)以及L和之后的实现,它将View的高程值更改为大于其他所有孩子。)

Parameters
c Canvas: The canvas which RecyclerView is drawing its children
recyclerView RecyclerView: The RecyclerView to which ItemTouchHelper is attached to
viewHolder RecyclerView.ViewHolder: The ViewHolder which is being interacted by the User or it was interacted and simply animating to its original position
dX float: The amount of horizontal displacement caused by user's action
dY float: The amount of vertical displacement caused by user's action
actionState int: The type of interaction on the View. Is either ACTION_STATE_DRAG or ACTION_STATE_SWIPE.
isCurrentlyActive boolean: True if this view is currently being controlled by the user or false it is simply animating back to its original state.

也可以看看:

onMove

boolean onMove (RecyclerView recyclerView, 
                RecyclerView.ViewHolder viewHolder, 
                RecyclerView.ViewHolder target)

当ItemTouchHelper想要将拖动的物品从旧位置移动到新位置时调用。

如果此方法返回true,则ItemTouchHelper假定 viewHolder已被移至适配器位置 target ViewHolder( ViewHolder#getAdapterPosition() )。

如果你不支持拖放,这个方法将永远不会被调用。

Parameters
recyclerView RecyclerView: The RecyclerView to which ItemTouchHelper is attached to.
viewHolder RecyclerView.ViewHolder: The ViewHolder which is being dragged by the user.
target RecyclerView.ViewHolder: The ViewHolder over which the currently active item is being dragged.
Returns
boolean True if the viewHolder has been moved to the adapter position of target.

也可以看看:

onMoved

void onMoved (RecyclerView recyclerView, 
                RecyclerView.ViewHolder viewHolder, 
                int fromPos, 
                RecyclerView.ViewHolder target, 
                int toPos, 
                int x, 
                int y)

onMove(RecyclerView, ViewHolder, ViewHolder)返回true时调用。

ItemTouchHelper在拖动时不会创建额外的位图或视图,而是会修改现有视图。 由于这个原因,视图在移动后仍然是布局的一部分是非常重要的。 当交换的视图接近RecyclerView边界或它们之间存在间隙时(例如其他视图不符合删除条件),这可能无法按预期工作。

该方法负责向LayoutManager提供必要的提示,以便它将视图保留在可见区域中。 例如,对于LinearLayoutManager,这与调用scrollToPositionWithOffset(int, int)一样简单。 如果视图的新位置可能超出范围,则默认实现将调用scrollToPosition(int)

确保ViewHolder保持可见状态非常重要,否则,如果移动导致视图超出范围,则可能会被LayoutManager移除。 在这种情况下,拖动会过早结束。

Parameters
recyclerView RecyclerView: The RecyclerView controlled by the ItemTouchHelper.
viewHolder RecyclerView.ViewHolder: The ViewHolder under user's control.
fromPos int: The previous adapter position of the dragged item (before it was moved).
target RecyclerView.ViewHolder: The ViewHolder on which the currently active item has been dropped.
toPos int: The new adapter position of the dragged item.
x int: The updated left value of the dragged View after drag translations are applied. This value does not include margins added by RecyclerView.ItemDecorations.
y int: The updated top value of the dragged View after drag translations are applied. This value does not include margins added by RecyclerView.ItemDecorations.

onSelectedChanged

void onSelectedChanged (RecyclerView.ViewHolder viewHolder, 
                int actionState)

当由ItemTouchHelper滑动或拖动的ViewHolder更改时调用。

If you override this method, you should call super.

Parameters
viewHolder RecyclerView.ViewHolder: The new ViewHolder that is being swiped or dragged. Might be null if it is cleared.
actionState int: One of ACTION_STATE_IDLE, ACTION_STATE_SWIPE or ACTION_STATE_DRAG.

也可以看看:

onSwiped

void onSwiped (RecyclerView.ViewHolder viewHolder, 
                int direction)

当用户刷新ViewHolder时调用。

如果要返回相对方向( STARTEND从) getMovementFlags(RecyclerView, ViewHolder)方法,这个方法也将使用相对方向。 否则,它将使用绝对方向。

如果您不支持滑动,则永远不会调用此方法。

ItemTouchHelper将保持对视图的引用,直到它从RecyclerView分离。 一旦它被分离,ItemTouchHelper将会调用clearView(RecyclerView, ViewHolder)

Parameters
viewHolder RecyclerView.ViewHolder: The ViewHolder which has been swiped by the user.
direction int: The direction to which the ViewHolder is swiped. It is one of UP, DOWN, LEFT or RIGHT. If your getMovementFlags(RecyclerView, ViewHolder) method returned relative flags instead of LEFT / RIGHT; `direction` will be relative as well. (START or END).

Hooray!