Android Ontouch event distribution mechanism

Source: Internet
Author: User

Events such as Onclick,onlongclick,onfling,onscroll in Android are made up of multiple Ontouch events, and a complete touchscreen event must contain 1 Action_down (pressed), multiple action_ Move, 1 action_up (release), touch event distribution is the process by which these events rotate between viewgroup and view.

1, ViewGroup inheritance View,view contains Dispatchtouchevent and ontouchevent two and event distribution directly related to two methods, ViewGroup also defines a onintercepttouchevent method in addition to rewriting the view's Dispatchtouchevent method;

Dispatchtouchevent:touch the initiator of the event distribution, each touch event must first call the method

Onintercepttouchevent: Exists only in the ViewGroup container, which determines whether the current event can be passed to the Groupview child control view

Ontouchevent: Receive and Process event, return value True indicates consumption of current event

2, for a viewgroup touch event, the first trigger is the dispatchtouchevent, The Dispatchtouchevent method invokes the Onintercepttouchevent method to determine whether an event is a ontouchevent event that is passed to ViewGroup ontouchevent or a child view

Look at the following onintercepttouchevent calling code

Final Booleanintercepted; if(actionmasked = =Motionevent.action_down|| Mfirsttouchtarget! =NULL) {                Final BooleanDisallowintercept = (Mgroupflags & flag_disallow_intercept)! = 0; if(!disallowintercept) {Intercepted=onintercepttouchevent (EV); Ev.setaction (action); //Restore action in case it was changed}Else{intercepted=false; }            } Else {                //There is no touch targets and this action is not a initial down//So the view group continues to intercept touches.intercepted =true; }
intercepted ==true is to indicate that the parent container will intercept the touchscreen event and that subsequent events will not be passed to the child view;Mfirsttouchtarget means the child view,flag_disallow_ that consumed the Touch_down event Intercept indicates whether the child view setting allows the event to be truncated by the parent container

Android Ontouch event distribution mechanism

Related Article

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.