Android Event distribution mechanism

Source: Internet
Author: User

all the click events must be The Motionevent.action_down event begins with the Motionevent.action_up end, the middle may be accompanied by Motionevent.action_move or other events, when the user taps the screen, it triggers the first Motionevent.action_down Events,

The point solution event was first taken by the activity's internal The dispatchtouchevent () method captures if we are in the process of copying an activity the Dispatchtouchevent () method returns TRUE or false directly, without calling Super. The dispatchtouchevent () method does not cause the event to pass to the top-level view in the activity layout, meaning that steps ① and the view inside the ViewGroup and ViewGroup are not executed. The ontouchevent() method in activity is not called.

      in an Activity dispatchtouchevent () The method calls the Super.dispatchtouchevent () method under the premise of , if we viewgroup the Dispatchtouchevent () in the activity's layout to return true directly, Indicates that the event was consumed by the current ViewGroup dispatchtouchevent () method without continuing to pass the event on to the ViewGroup onintercepttouchevent () and ontouchevent (), Because events are consumed in the ViewGroup, the same events will not continue to be thought of as ViewGroup's parent ViewGroup and the Ontouchevent () method of the activity. If you consume Motionevent.action_down, if all the upper ViewGroup are not intercepted, the subsequent Motionevent.action_ The up is also passed to the ViewGroup dispatchtouchevent (). If you return false directly, it means that there is no consumption, and the event is passed along the upper level, Upper ViewGroup ontouchevent (), and if there is no consumption at all, it will eventually return to the activity's Ontouchevent () method.   Then the Motionevent.action_down is passed directly by the activity's dispatchtouchevent () to Ontouchevent (), not the layout viewgroup and all the child views are passed. If the current ViewGroup call  super.dispatchtouchevent (); Hedghog (the event is passed to the ViewGroup onintercepttouchevent ()

Onintercepttouchevent () indicates whether to intercept whether the current event wants the next level of sub-view or ViewGroup pass, and if True is directly returned, the event is passed directly to ViewGroup's Ontouchevent (). Returns false to the next-level view or ViewGroup dispatchtouchevent (). If the Ontouchevent () is passed directly to the current view, if the ontouchevent () This event is consumed and the return value is true, and subsequent motionevent.action_up are passed to the ViewGroup ontouchevent () if they are not intercepted. If the call is Super.onintercepttouchevent (), then the processing logic of the method depends on the inherited parent class.

The bottom view is a direct or indirect subclass that inherits from view or does not have a child view, without the Onintercepttouchevent () method, but Dispatchtouchevent () and Ontouchevent () The processing logic is similar to the viewgroup in the middle.

Android Event distribution mechanism

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.