public class ViewDragHelper extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
ViewDragHelper.Callback
A Callback is used as a communication channel with the ViewDragHelper
back to the parent view using it.
|
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DIRECTION_ALL
Indicates that a check should occur along all axes
|
static int |
DIRECTION_HORIZONTAL
Indicates that a check should occur along the horizontal axis
|
static int |
DIRECTION_VERTICAL
Indicates that a check should occur along the vertical axis
|
static int |
EDGE_ALL
Edge flag set indicating all edges should be affected.
|
static int |
EDGE_BOTTOM
Edge flag indicating that the bottom edge should be affected.
|
static int |
EDGE_LEFT
Edge flag indicating that the left edge should be affected.
|
static int |
EDGE_RIGHT
Edge flag indicating that the right edge should be affected.
|
static int |
EDGE_SIZE |
static int |
EDGE_TOP
Edge flag indicating that the top edge should be affected.
|
static int |
INVALID_POINTER
A null/invalid pointer ID.
|
static int |
STATE_DRAGGING
A view is currently being dragged.
|
static int |
STATE_IDLE
A view is not currently being dragged or animating as a result of a
fling/snap.
|
static int |
STATE_SETTLING
A view is currently settling into place as a result of a fling or
predefined non-interactive motion.
|
| 限定符和类型 | 方法和说明 |
|---|---|
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(MotionEvent) receiving an
ACTION_CANCEL event. |
protected boolean |
canScroll(android.view.View v,
boolean checkV,
int dx,
int dy,
int x,
int y)
Tests scrollability within child views of v given a delta of dx.
|
void |
captureChildView(android.view.View childView,
int activePointerId)
Capture a specific child view for dragging within the parent.
|
boolean |
checkTouchSlop(int directions)
Check if any pointer tracked in the current gesture has crossed the
required slop threshold.
|
boolean |
checkTouchSlop(int directions,
int pointerId)
Check if the specified 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(android.view.ViewGroup forParent,
float sensitivity,
ViewDragHelper.Callback cb)
Factory method to create a new ViewDragHelper.
|
static ViewDragHelper |
create(android.view.ViewGroup forParent,
ViewDragHelper.Callback cb)
Factory method to create a new ViewDragHelper.
|
android.view.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() |
android.view.View |
getCapturedView() |
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(android.view.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(android.view.MotionEvent ev)
Process a touch event received by the parent view.
|
void |
setEdgeSize(int size)
Set the size of an edge.
|
void |
setEdgeTrackingEnabled(int edgeFlags)
Enable edge tracking for the selected edges of the parent view.
|
void |
setMinVelocity(float minVel)
Set the minimum velocity that will be detected as having a magnitude
greater than zero in pixels per second.
|
boolean |
settleCapturedViewAt(int finalLeft,
int finalTop)
Settle the captured view at the given (left, top) position.
|
boolean |
shouldInterceptTouchEvent(android.view.MotionEvent ev)
Check if this event as provided to the parent view's
onInterceptTouchEvent should cause the parent to intercept the touch
event stream.
|
boolean |
smoothSlideViewTo(android.view.View child,
int finalLeft,
int finalTop)
Animate the view
child to the given (left, top) position. |
public static final int INVALID_POINTER
public static final int STATE_IDLE
public static final int STATE_DRAGGING
public static final int STATE_SETTLING
public static final int EDGE_LEFT
public static final int EDGE_RIGHT
public static final int EDGE_TOP
public static final int EDGE_BOTTOM
public static final int EDGE_ALL
public static final int DIRECTION_HORIZONTAL
public static final int DIRECTION_VERTICAL
public static final int DIRECTION_ALL
public static final int EDGE_SIZE
public static ViewDragHelper create(android.view.ViewGroup forParent, ViewDragHelper.Callback cb)
forParent - Parent view to monitorcb - Callback to provide information and receive eventspublic static ViewDragHelper create(android.view.ViewGroup forParent, float sensitivity, ViewDragHelper.Callback cb)
forParent - Parent view to monitorsensitivity - 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 eventspublic void setMinVelocity(float minVel)
minVel - Minimum velocity to detectpublic float getMinVelocity()
public int getViewDragState()
STATE_IDLE, STATE_DRAGGING or STATE_SETTLING.public void setEdgeTrackingEnabled(int edgeFlags)
edgeFlags - Combination of edge flags describing the edges to watchEDGE_LEFT,
EDGE_TOP,
EDGE_RIGHT,
EDGE_BOTTOMpublic int getEdgeSize()
setEdgeTrackingEnabled(int)public void setEdgeSize(int size)
size - The size of an edge in pixelspublic void captureChildView(android.view.View childView,
int activePointerId)
childView - Child view to captureactivePointerId - ID of the pointer that is dragging the captured child viewpublic android.view.View getCapturedView()
public int getActivePointerId()
INVALID_POINTER.public int getTouchSlop()
public void cancel()
processTouchEvent(MotionEvent) receiving an
ACTION_CANCEL event.public void abort()
cancel(), but also abort all motion in progress and snap to the
end of any animation.public boolean smoothSlideViewTo(android.view.View child,
int finalLeft,
int finalTop)
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 animatefinalLeft - Final left position of childfinalTop - Final top position of childcontinueSettling(boolean) callspublic boolean settleCapturedViewAt(int finalLeft,
int finalTop)
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 viewfinalTop - Settled top edge position for the captured viewcontinueSettling(boolean) callspublic void flingCapturedView(int minLeft,
int minTop,
int maxLeft,
int maxTop)
continueSettling(boolean) on each
subsequent frame to continue the motion until it returns false.minLeft - Minimum X position for the view's left edgeminTop - Minimum Y position for the view's top edgemaxLeft - Maximum X position for the view's left edgemaxTop - Maximum Y position for the view's top edgepublic boolean continueSettling(boolean deferCallbacks)
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
View.computeScroll() or similar methods
invoked as part of layout or drawing.public boolean isPointerDown(int pointerId)
The state used to report this information is populated by the methods
shouldInterceptTouchEvent(MotionEvent) or
processTouchEvent(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
MotionEventprotected boolean canScroll(android.view.View v,
boolean checkV,
int dx,
int dy,
int x,
int y)
v - View to test for horizontal scrollabilitycheckV - 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 axisdy - Delta scrolled in pixels along the Y axisx - X coordinate of the active touch pointy - Y coordinate of the active touch pointpublic boolean shouldInterceptTouchEvent(android.view.MotionEvent ev)
ev - MotionEvent provided to onInterceptTouchEventpublic void processTouchEvent(android.view.MotionEvent ev)
ev - The touch event received by the parent viewpublic boolean checkTouchSlop(int directions)
This depends on internal state populated by
shouldInterceptTouchEvent(MotionEvent) or
processTouchEvent(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_ALLpublic boolean checkTouchSlop(int directions,
int pointerId)
This depends on internal state populated by
shouldInterceptTouchEvent(MotionEvent) or
processTouchEvent(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_ALLpointerId - ID of the pointer to slop check as specified by MotionEventpublic boolean isEdgeTouched(int edges)
edges - Edges to check for an initial edge touch. See
EDGE_LEFT, EDGE_TOP, EDGE_RIGHT,
EDGE_BOTTOM and EDGE_ALLpublic boolean isEdgeTouched(int edges,
int pointerId)
edges - Edges to check for an initial edge touch. See
EDGE_LEFT, EDGE_TOP, EDGE_RIGHT,
EDGE_BOTTOM and EDGE_ALLpublic boolean isCapturedViewUnder(int x,
int y)
x - X position to test in the parent's coordinate systemy - Y position to test in the parent's coordinate systempublic boolean isViewUnder(android.view.View view,
int x,
int y)
view - Child view of the parent to hit testx - X position to test in the parent's coordinate systemy - Y position to test in the parent's coordinate systempublic android.view.View findTopChildUnder(int x,
int y)
x - X position to test in the parent's coordinate systemy - Y position to test in the parent's coordinate system