java.lang.Object | |
↳ | android.support.v4.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.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
cancel() , but also abort all motion in progress and snap to the end of any
animation. | |||||||||||
The result of a call to this method is equivalent to
processTouchEvent(android.view.MotionEvent) receiving an ACTION_CANCEL event. | |||||||||||
Capture a specific child view for dragging within the parent.
| |||||||||||
Check if the specified pointer tracked in the current gesture has crossed
the required slop threshold.
| |||||||||||
Check if any pointer tracked in the current gesture has crossed
the required slop threshold.
| |||||||||||
Move the captured settling view by the appropriate amount for the current time.
| |||||||||||
Factory method to create a new ViewDragHelper.
| |||||||||||
Factory method to create a new ViewDragHelper.
| |||||||||||
Find the topmost child under the given point within the parent view's coordinate system.
| |||||||||||
Settle the captured view based on standard free-moving fling behavior.
| |||||||||||
Return the size of an edge.
| |||||||||||
Return the currently configured minimum velocity.
| |||||||||||
Retrieve the current drag state of this helper.
| |||||||||||
Determine if the currently captured view is under the given point in the
parent view's coordinate system.
| |||||||||||
Check if any of the edges specified were initially touched in the currently active gesture.
| |||||||||||
Check if any of the edges specified were initially touched by the pointer with
the specified ID.
| |||||||||||
Check if the given pointer ID represents a pointer that is currently down (to the best
of the ViewDragHelper's knowledge).
| |||||||||||
Determine if the supplied view is under the given point in the
parent view's coordinate system.
| |||||||||||
Process a touch event received by the parent view.
| |||||||||||
Enable edge tracking for the selected edges of the parent view.
| |||||||||||
Set the minimum velocity that will be detected as having a magnitude greater than zero
in pixels per second.
| |||||||||||
Settle the captured view at the given (left, top) position.
| |||||||||||
Check if this event as provided to the parent view's onInterceptTouchEvent should
cause the parent to intercept the touch event stream.
| |||||||||||
Animate the view
child to the given (left, top) position. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Tests scrollability within child views of v given a delta of dx.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Indicates that a check should occur along all axes
Indicates that a check should occur along the horizontal axis
Indicates that a check should occur along the vertical axis
Edge flag set indicating all edges should be affected.
Edge flag indicating that the bottom edge should be affected.
Edge flag indicating that the left edge should be affected.
Edge flag indicating that the right edge should be affected.
Edge flag indicating that the top edge should be affected.
A null/invalid pointer ID.
A view is currently being dragged. The position is currently changing as a result of user input or simulated user input.
A view is not currently being dragged or animating as a result of a fling/snap.
A view is currently settling into place as a result of a fling or predefined non-interactive motion.
cancel()
, but also abort all motion in progress and snap to the end of any
animation.
The result of a call to this method is equivalent to
processTouchEvent(android.view.MotionEvent)
receiving an ACTION_CANCEL event.
Capture a specific child view for dragging within the parent. The callback will be notified
but tryCaptureView(android.view.View, int)
will not be asked permission to
capture this view.
childView | Child view to capture |
---|---|
activePointerId | ID of the pointer that is dragging the captured child view |
Check if the specified pointer tracked in the current gesture has crossed the required slop threshold.
This depends on internal state populated by
shouldInterceptTouchEvent(android.view.MotionEvent)
or
processTouchEvent(android.view.MotionEvent)
. You should only rely on
the results of this method after all currently available touch data
has been provided to one of these two methods.
directions | Combination of direction flags, see DIRECTION_HORIZONTAL ,
DIRECTION_VERTICAL , DIRECTION_ALL |
---|---|
pointerId | ID of the pointer to slop check as specified by MotionEvent |
Check if any pointer tracked in the current gesture has crossed the required slop threshold.
This depends on internal state populated by
shouldInterceptTouchEvent(android.view.MotionEvent)
or
processTouchEvent(android.view.MotionEvent)
. You should only rely on
the results of this method after all currently available touch data
has been provided to one of these two methods.
directions | Combination of direction flags, see DIRECTION_HORIZONTAL ,
DIRECTION_VERTICAL , DIRECTION_ALL |
---|
Move the captured settling view by the appropriate amount for the current time.
If continueSettling
returns true, the caller should call it again
on the next frame to continue.
deferCallbacks | true if state callbacks should be deferred via posted message.
Set this to true if you are calling this method from
computeScroll() or similar methods
invoked as part of layout or drawing. |
---|
Factory method to create a new ViewDragHelper.
forParent | Parent view to monitor |
---|---|
cb | Callback to provide information and receive events |
Factory method to create a new ViewDragHelper.
forParent | Parent view to monitor |
---|---|
sensitivity | Multiplier for how sensitive the helper should be about detecting the start of a drag. Larger values are more sensitive. 1.0f is normal. |
cb | Callback to provide information and receive events |
Find the topmost child under the given point within the parent view's coordinate system.
The child order is determined using getOrderedChildIndex(int)
.
x | X position to test in the parent's coordinate system |
---|---|
y | Y position to test in the parent's coordinate system |
Settle the captured view based on standard free-moving fling behavior.
The caller should invoke continueSettling(boolean)
on each subsequent frame
to continue the motion until it returns false.
minLeft | Minimum X position for the view's left edge |
---|---|
minTop | Minimum Y position for the view's top edge |
maxLeft | Maximum X position for the view's left edge |
maxTop | Maximum Y position for the view's top edge |
INVALID_POINTER
.
Return the size of an edge. This is the range in pixels along the edges of this view that will actively detect edge touches or drags if edge tracking is enabled.
Return the currently configured minimum velocity. Any flings with a magnitude less than this value in pixels per second. Callback methods accepting a velocity will receive zero as a velocity value if the real detected velocity was below this threshold.
Retrieve the current drag state of this helper. This will return one of
STATE_IDLE
, STATE_DRAGGING
or STATE_SETTLING
.
Determine if the currently captured view is under the given point in the parent view's coordinate system. If there is no captured view this method will return false.
x | X position to test in the parent's coordinate system |
---|---|
y | Y position to test in the parent's coordinate system |
Check if any of the edges specified were initially touched in the currently active gesture. If there is no currently active gesture this method will return false.
edges | Edges to check for an initial edge touch. See EDGE_LEFT ,
EDGE_TOP , EDGE_RIGHT , EDGE_BOTTOM and
EDGE_ALL |
---|
Check if any of the edges specified were initially touched by the pointer with the specified ID. If there is no currently active gesture or if there is no pointer with the given ID currently down this method will return false.
edges | Edges to check for an initial edge touch. See EDGE_LEFT ,
EDGE_TOP , EDGE_RIGHT , EDGE_BOTTOM and
EDGE_ALL |
---|
Check if the given pointer ID represents a pointer that is currently down (to the best of the ViewDragHelper's knowledge).
The state used to report this information is populated by the methods
shouldInterceptTouchEvent(android.view.MotionEvent)
or
processTouchEvent(android.view.MotionEvent)
. If one of these methods has not
been called for all relevant MotionEvents to track, the information reported
by this method may be stale or incorrect.
pointerId | pointer ID to check; corresponds to IDs provided by MotionEvent |
---|
Determine if the supplied view is under the given point in the parent view's coordinate system.
view | Child view of the parent to hit test |
---|---|
x | X position to test in the parent's coordinate system |
y | Y position to test in the parent's coordinate system |
Process a touch event received by the parent view. This method will dispatch callback events as needed before returning. The parent view's onTouchEvent implementation should call this.
ev | The touch event received by the parent view |
---|
Enable edge tracking for the selected edges of the parent view.
The callback's onEdgeTouched(int, int)
and
onEdgeDragStarted(int, int)
methods will only be invoked
for edges for which edge tracking has been enabled.
edgeFlags | Combination of edge flags describing the edges to watch |
---|
Set the minimum velocity that will be detected as having a magnitude greater than zero in pixels per second. Callback methods accepting a velocity will be clamped appropriately.
minVel | Minimum velocity to detect |
---|
Settle the captured view at the given (left, top) position.
The appropriate velocity from prior motion will be taken into account.
If this method returns true, the caller should invoke continueSettling(boolean)
on each subsequent frame to continue the motion until it returns false. If this method
returns false there is no further work to do to complete the movement.
finalLeft | Settled left edge position for the captured view |
---|---|
finalTop | Settled top edge position for the captured view |
continueSettling(boolean)
calls
Check if this event as provided to the parent view's onInterceptTouchEvent should cause the parent to intercept the touch event stream.
ev | MotionEvent provided to onInterceptTouchEvent |
---|
Animate the view child
to the given (left, top) position.
If this method returns true, the caller should invoke continueSettling(boolean)
on each subsequent frame to continue the motion until it returns false. If this method
returns false there is no further work to do to complete the movement.
This operation does not count as a capture event, though getCapturedView()
will still report the sliding view while the slide is in progress.
child | Child view to capture and animate |
---|---|
finalLeft | Final left position of child |
finalTop | Final top position of child |
continueSettling(boolean)
calls
Tests scrollability within child views of v given a delta of dx.
v | View to test for horizontal scrollability |
---|---|
checkV | Whether the view v passed should itself be checked for scrollability (true), or just its children (false). |
dx | Delta scrolled in pixels along the X axis |
dy | Delta scrolled in pixels along the Y axis |
x | X coordinate of the active touch point |
y | Y coordinate of the active touch point |