android development: exploring learning Android Touch event distribution delivery mechanisms (a)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_39027256/article/details/102769022

First posted flow chart:

 1. When I click on the screen we trigger Activity of dispatchTouchEvent () method, if it returns true or false represents the event to be consumed (not passed on), return to super () dispatchTouchEvent ViewGroup's () method will spread.

2. When the dispatchTouchEvent ViewGroup () method returns true, the event is on behalf of the consumer. If false is returned to the event will return to the onTouchEvent Activity () method for processing, return super () is passed to onInterceptTouchEvent ViewGroup the event () method, onInterceptTouchEvent () returns true representatives intercept the event, put the event to ViewGroup the onTouchEvent () method of treatment, if it returns false or super (), represents not intercept the event, the event is passed to the View of dispatchTouchEvent ()

3. When the view of dispatchTouchEvent () returns true when the same event is on behalf of the consumer, it returns false, the event will be delivered to onTouchEvent ViewGroup of () to return to super () events to View the onTouchEvent () method, onTouchEvent () returns ture representatives event is consumed, he returns false if the event delivery onTouchEvent back on the floor ();

to sum up:

For dispatchTouchEvent () Method:

  • return true: consumed event, termination of delivery.
  • return false: pass events to onTouchEvent () method of the parent View. If Activity of dispatchTouchEvent () method, the event is consumed, terminate transfer.
  • return super: If Activity, then passed to the next level view (viewGroup) of dispatchTouchEvent; if it is ViewGroup, then passed to his onInterceptTouchEvent (); if a View, then passed to his onTouchEvent ().


For onInterceptTouchEvent () method:

  • return true: the event is passed to ViewGroup own onTouchEvent () method for processing.
  • return false / super: dispatchTouchEvent will pass the event to the next level View ().
  • onInterceptTouchEvent () method is unique viewGrounp

For onTouchEvent () Method:

  • return true: consumed event, termination of delivery.
  • return false / super: pass events to onTouchEvent () method on a view of.
  • Activity of onTouchEvent () method will return no matter what the event is terminated

Read a lot of articles online, written not very good, especially painting pictures of foggy, it all can not read. The Nuggets have finally found a good article written by:

https://juejin.im/post/5a0fab1bf265da432d27ad70

Guess you like

Origin blog.csdn.net/qq_39027256/article/details/102769022