ItemTouchHelper
open class ItemTouchHelper : RecyclerView.ItemDecoration, RecyclerView.OnChildAttachStateChangeListener
kotlin.Any | ||
↳ | androidx.recyclerview.widget.RecyclerView.ItemDecoration | |
↳ | androidx.recyclerview.widget.ItemTouchHelper |
This is a utility class to add swipe to dismiss and drag & drop support to RecyclerView.
It works with a RecyclerView and a Callback class, which configures what type of interactions are enabled and also receives events when user performs these actions.
Depending on which functionality you support, you should override Callback#onMove(RecyclerView, ViewHolder, ViewHolder)
and / or Callback#onSwiped(ViewHolder, int)
.
This class is designed to work with any LayoutManager but for certain situations, it can be optimized for your custom LayoutManager by extending methods in the ItemTouchHelper.Callback
class or implementing ItemTouchHelper.ViewDropHandler
interface in your LayoutManager.
By default, ItemTouchHelper moves the items' translateX/Y properties to reposition them. You can customize these behaviors by overriding Callback#onChildDraw(Canvas, RecyclerView, * ViewHolder, float, float, int, boolean)
or Callback#onChildDrawOver(Canvas, RecyclerView, ViewHolder, float, float, int, * boolean)
.
onChildDraw
.
Summary
Nested classes | |
---|---|
abstract |
This class is the contract between ItemTouchHelper and your application. |
abstract |
A simple wrapper to the default Callback which you can construct with drag and swipe directions and this class will handle the flag callbacks. |
abstract |
An interface which can be implemented by LayoutManager for better integration with |
Constants | |
---|---|
static Int |
A View is currently being dragged. |
static Int |
ItemTouchHelper is in idle state. |
static Int |
A View is currently being swiped. |
static Int |
Animation type for views that were dragged and now will animate to their final position. |
static Int |
Animation type for views which are not completely swiped thus will animate back to their original position. |
static Int |
Animation type for views which are swiped successfully. |
static Int |
Down direction, used for swipe & drag control. |
static Int |
Horizontal end direction. |
static Int |
Left direction, used for swipe & drag control. |
static Int |
Right direction, used for swipe & drag control. |
static Int |
Horizontal start direction. |
static Int |
Up direction, used for swipe & drag control. |
Public constructors | |
---|---|
<init>(@NonNull callback: ItemTouchHelper.Callback) Creates an ItemTouchHelper that will work with the given Callback. |
Public methods | |
---|---|
open Unit |
attachToRecyclerView(@Nullable recyclerView: RecyclerView?) Attaches the ItemTouchHelper to the provided RecyclerView. |
open Unit |
getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) |
open Unit |
onChildViewAttachedToWindow(@NonNull view: View) |
open Unit |
onChildViewDetachedFromWindow(@NonNull view: View) |
open Unit |
onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) |
open Unit |
onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) |
open Unit |
startDrag(@NonNull viewHolder: RecyclerView.ViewHolder) Starts dragging the provided ViewHolder. |
open Unit |
startSwipe(@NonNull viewHolder: RecyclerView.ViewHolder) Starts swiping the provided ViewHolder. |
Inherited functions | |
---|---|