onMoved

open fun onMoved(@NonNull recyclerView: RecyclerView, @NonNull viewHolder: RecyclerView.ViewHolder, fromPos: Int, @NonNull target: RecyclerView.ViewHolder, toPos: Int, x: Int, y: Int)(source)

Called when onMove returns true.

ItemTouchHelper does not create an extra Bitmap or View while dragging, instead, it modifies the existing View. Because of this reason, it is important that the View is still part of the layout after it is moved. This may not work as intended when swapped Views are close to RecyclerView bounds or there are gaps between them (e.g. other Views which were not eligible for dropping over).

This method is responsible to give necessary hint to the LayoutManager so that it will keep the View in visible area. For example, for LinearLayoutManager, this is as simple as calling scrollToPositionWithOffset. Default implementation calls scrollToPosition if the View's new position is likely to be out of bounds.

It is important to ensure the ViewHolder will stay visible as otherwise, it might be removed by the LayoutManager if the move causes the View to go out of bounds. In that case, drag will end prematurely.

Parameters

recyclerView

The RecyclerView controlled by the ItemTouchHelper.

viewHolder

The ViewHolder under user's control.

fromPos

The previous adapter position of the dragged item (before it was moved).

target

The ViewHolder on which the currently active item has been dropped.

toPos

The new adapter position of the dragged item.

x

The updated left value of the dragged View after drag translations are applied. This value does not include margins added by RecyclerView.ItemDecorations.

y

The updated top value of the dragged View after drag translations are applied. This value does not include margins added by RecyclerView.ItemDecorations.