Android DragViewHelper

ViewDragHelper

ViewDragHelper is in support.v4. It 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.

So it’s for moving Views in ViewGroup!. For example, customize a LinearLayout in which we could drag views.

Detect Touch Event

Those above ViewDragHelper.Callbacks will be called when ViewGroup detects touch event.

It needs to override two functions in ViewGroup:

onInterceptTouchEvent() - In it, using mDraggerView.shouldInterceptTouchEvent(event) to decide if it should intercept this touch event or not.

onTouchEvent() - In it, using mDraggerView.processTouchEvent(event) to process the motion event.

onInterceptTouchEvent() is called whenever a touch event is detected on the surface of a ViewGroup, including on the surface of its children. If it returns true, the MotionEvent is intercepted, meaning it will be not be passed on to the child, but rather to onTouchEvent() method of ViewGroup.