拖拽ViewDragHelper

ViewDragHelper:

shouldInterceptTouchEvent(MotionEvent ev)处理事件分发的(怎么说这个方法呢?主要是将ViewGroup的事件分发,委托给ViewDragHelper进行处理)


processTouchEvent(MotionEvent event)处理相应TouchEvent的方法,这里要注意一个问题,处理相应的TouchEvent的时候要将结果返回为true,消费本次事件!否则将无法使用ViewDragHelper处理相应的拖拽事件!

smoothSlideViewTo( View child, int finalLeft, int finalTop) 回弹

ViewDragHelper.Callback:

tryCaptureView(View child, int pointerId)这是一个抽象类,必须去实现,也只有在这个方法返回true的时候下面的方法才会生效:

onViewDragStateChanged(int state) 当状态改变的时候回调,返回相应的状态(这里有三种状态)

STATE_IDLE 闲置状态

STATE_DRAGGING 正在拖动

STATE_SETTLING 放置到某个位置

onViewPositionChanged(View changedView, int left, int top, int dx, int dy)当你拖动的View位置发生改变的时候回调

onViewCaptured(View capturedChild, int activePointerId)捕获View的时候调用的方法

onViewReleased(View releasedChild, float xvel, float yvel) 当View停止拖拽的时候调用的方法,一般在这个方法中重置一些参数,比如回弹什么的。。。

getViewVerticalDragRange(View child)竖直拖拽的边界

clampViewPositionVertical(View child, int top, int dy) 竖直拖拽的时候回调的方法

clampViewPositionHorizontal(View child, int left, int dx) 水平拖拽的时候回调的方法

你可能感兴趣的:(拖拽ViewDragHelper)