DispatchTouchEvent:

  • Method returns true to indicate that the event is consumed by the current view;
  • Return super.dispatchTouchEvent to continue distributing the event,
  • A return of false indicates onTouchEvent processing to the parent class.

OnInterceptTouchEvent:

  • Method returns true to intercept the event and send it to its own onTouchEvent method for consumption;
  • Returning false means no interception and needs to continue to be passed to the subview.
  • If return super. OnInterceptTouchEvent (ev), event interceptor in two situations:
  1. If the View has a child View and the child View is clicked, it will not be intercepted and continue to be distributed to the child View for processing, equivalent to return false.
  2. If the View has no children or children but does not click on the subview (the ViewGroup is the normal View), the onTouchEvent response is sent to the View, which is equivalent to return True.

Viewgroups such as LinearLayout, RelativeLayout, and FrameLayout are not blocked by default, whereas viewgroups such as ScrollView and ListView are blocked by default.

OnTouchEvent:

  • Method returns true to indicate that the current view can process the corresponding event;
  • A return value of false means that the event is not handled by the current view and is passed to the parent view’s onTouchEvent method for processing.
  • If return super.onTouchEvent(EV), event handling is divided into two cases:
  1. If the View is clickable or longClickable, true is returned, indicating that the event was consumed, just as true is returned;
  2. If the View is not clickable or LongClickable, false is returned, indicating that the event is not consumed and will be passed up, just as false is returned.

Some important conclusions:

  1. Note: In Android, there are three classes with event-passing capabilities:
  • Activity: Has both distribution and consumption methods.
  • ViewGroup: has distribute, intercept, and consume methods.
  • View: Has distribution and consumption methods.
  1. Event delivery priority:
  • OnTouch > onTouchEvent > onClickListener.onclick.
  1. Normally, a time series can only be intercepted and consumed by one View. Because once an element intercepts the event, all events in the same sequence are handed to it directly (that is, the View’s interception method is no longer called to ask it whether to intercept, but the remaining ACTION_MOVE, ACTION_DOWN, etc.). Exception: You can force the event to be handled by another View by returning false to the onTouchEvent that overrides the View.
  2. If the View consumes no events other than ACTION_DOWN, the click event will disappear, the parent element’s onTouchEvent will not be called, and the current View will continue to receive subsequent events, which will eventually be passed on to the Activity.
  3. ViewGroup does not intercept any events by default (return false).
  4. A View’s onTouchEvent will consume the event by default (returning true), unless it is unclickable (both Clickable and longClickable are false). The longClickable property of a View is false by default. The Clickable property of a Button is true by default and that of a TextView is false by default.
  5. The Enable property of the View does not affect the default return value of onTouchEvent.
  6. Through requestDisallowInterceptTouchEvent method can intervene in the parent element in child elements distribution of events, except ACTION_DOWN events.