Gesture events, html5 gesture events
1. Basic Gesture events
There are three main methods:
DispatchTouchEvent: determines whether the event needs to be issued. If "true" is returned, it is delivered to the lower-level view. If "false" is returned, it is not required to be delivered (to its own onTouchEvent ). However, whether the event is finally delivered depends on the interception result of onInterceptTouchEvent.
OnInterceptTouchEvent: determines whether the current container needs to intercept the event. If the return value is true, it indicates that the event is intercepted (the onTouchEvent is handled by itself), not to the lower-level view, and false indicates that the event is not intercepted.
OnTouchEvent: determines whether the event has been processed. If true is returned, the onTouchEvent of the upper-level view is not required. If "false" is returned, the event is not completed. The onTouchEvent in the upper-level view is processed, and then the upper-level onTouchEvent is returned to determine whether the event is directly ended or processed by the upper-level.
2. performer of the gesture Method
Page class: includes the derived classes of Activity and Activity. The page class can operate on dispatchTouchEvent and onTouchEvent. Note that Fragment does not support basic gesture methods. You can only implement the OnTouchListener interface to respond to gesture events.
Controls: Controls derived from the View class, including TextView, ImageView, And Button, and Their Derived classes. The control class can operate on dispatchTouchEvent and onTouchEvent.
Container class: includes various containers derived from the ViewGroup class, such as three layout, RelativeLayout, FrameLayout, and GridView, ListView, and Spinner derived from AdapterView, as well as ViewPager and ViewFlipper. The container class can operate on dispatchTouchEvent, onInterceptTouchEvent, and onTouchEvent.
As shown above, only the container class can operate the onInterceptTouchEvent method, because this method is used to intercept events sent to the lower-layer view, and the control class is already at the bottom layer. Only intercepted parts are not intercepted, similarly, the page class itself does not have a lower-level view.
3. lifecycle of a gesture event
Control response
Activity. dispatchTouchEvent (return true)-> ViewGroup. dispatchTouchEvent (return true)-> ViewGroup. onInterceptTouchEvent (return false)-> View. dispatchTouchEvent (return true)-> View. onTouchEvent (return true)-> end
Container response
Method 1: Activity. dispatchTouchEvent (return true)-> ViewGroup. dispatchTouchEvent (return false)-> ViewGroup. onTouchEvent (return true)-> end
Method 2: Activity. dispatchTouchEvent (return true)-> ViewGroup. dispatchTouchEvent (return true)-> ViewGroup. onInterceptTouchEvent (return true)-> ViewGroup. onTouchEvent (return true)-> end
Method 3: Activity. dispatchTouchEvent (return true)-> ViewGroup. dispatchTouchEvent (return true)-> ViewGroup. onInterceptTouchEvent (return false)-> View. dispatchTouchEvent (return true or false)-> View. onTouchEvent (false)-> ViewGroup. onTouchEvent (return true)-> end
Activity response
Activity. dispatchTouchEvent (return false)-> Activity. onTouchEvent (return true)-> end
For more detailed lifecycles, see:
4. TouchEvent
The following are common methods of touch events:
GetAction: Get the current action
GetX: obtains the relative coordinate X of the current control.
GetY: obtains the relative coordinate Y of the current control.
GetRawX: obtains the relative coordinate X of the current screen.
GetRawY: obtains the relative coordinate Y of the current screen.
GetEventTime: Get the current event time