ViewDragHelper

public class ViewDragHelper
extends Object

java.lang.Object
   ↳ androidx.customview.widget.ViewDragHelper


ViewDragHelper is a utility class for writing custom ViewGroups. It offers a number of useful operations and state tracking for allowing a user to drag and reposition views within their parent ViewGroup.

Summary

Nested classes

class ViewDragHelper.Callback

A Callback is used as a communication channel with the ViewDragHelper back to the parent view using it. 

Constants

int DIRECTION_ALL

Indicates that a check should occur along all axes

int DIRECTION_HORIZONTAL

Indicates that a check should occur along the horizontal axis

int DIRECTION_VERTICAL

Indicates that a check should occur along the vertical axis

int EDGE_ALL

Edge flag set indicating all edges should be affected.

int EDGE_BOTTOM

Edge flag indicating that the bottom edge should be affected.

int EDGE_LEFT

Edge flag indicating that the left edge should be affected.

int EDGE_RIGHT

Edge flag indicating that the right edge should be affected.

int EDGE_TOP

Edge flag indicating that the top edge should be affected.

int INVALID_POINTER

A null/invalid pointer ID.

int STATE_DRAGGING

A view is currently being dragged.

int STATE_IDLE

A view is not currently being dragged or animating as a result of a fling/snap.

int STATE_SETTLING

A view is currently settling into place as a result of a fling or predefined non-interactive motion.

Public methods

void abort()

cancel(), but also abort all motion in progress and snap to the end of any animation.

void cancel()

The result of a call to this method is equivalent to processTouchEvent(android.view.MotionEvent) receiving an ACTION_CANCEL event.

void captureChildView(View childView, int activePointerId)

Capture a specific child view for dragging within the parent.

boolean checkTouchSlop(int directions, int pointerId)

Check if the specified pointer tracked in the current gesture has crossed the required slop threshold.

boolean checkTouchSlop(int directions)

Check if any pointer tracked in the current gesture has crossed the required slop threshold.

boolean continueSettling(boolean deferCallbacks)

Move the captured settling view by the appropriate amount for the current time.

static ViewDragHelper create(ViewGroup forParent, ViewDragHelper.Callback cb)

Factory method to create a new ViewDragHelper.

static ViewDragHelper create(ViewGroup forParent, float sensitivity, ViewDragHelper.Callback cb)

Factory method to create a new ViewDragHelper.

View findTopChildUnder(int x, int y)

Find the topmost child under the given point within the parent view's coordinate system.

void flingCapturedView(int minLeft, int minTop, int maxLeft, int maxTop)

Settle the captured view based on standard free-moving fling behavior.

int getActivePointerId()
View getCapturedView()
int getDefaultEdgeSize()

Return the default size used for edge tracking.

int getEdgeSize()

Return the size of an edge.

float getMinVelocity()

Return the currently configured minimum velocity.

int getTouchSlop()
int getViewDragState()

Retrieve the current drag state of this helper.

boolean isCapturedViewUnder(int x, int y)

Determine if the currently captured view is under the given point in the parent view's coordinate system.

boolean isEdgeTouched(int edges)

Check if any of the edges specified were initially touched in the currently active gesture.

boolean isEdgeTouched(int edges, int pointerId)

Check if any of the edges specified were initially touched by the pointer with the specified ID.

boolean isPointerDown(int pointerId)

Check if the given pointer ID represents a pointer that is currently down (to the best of the ViewDragHelper's knowledge).

boolean isViewUnder(View view, int x, int y)

Determine if the supplied view is under the given point in the parent view's coordinate system.

void processTouchEvent(MotionEvent ev)

Process a touch event received by the parent view.

void setEdgeSize(int size)

Set the range in pixe