Android Screen Touch event mechanism

Source: Internet
Author: User

The types of events in Android are key events and screen touch events, and touch events are the underlying events of screen touch events, and it is necessary to understand them in depth.
One of the simplest screen touch actions triggered a series of touch events:action_down->action_move->action_move->action_move...->action_move-> Action_up
When the screen contains a viewgroup, and the ViewGroup contains a sub-view, how does the Android system handle the touch event? Is it viewgroup to handle the touch event or the child view to handle the touch event? I can only be sure to say to you not necessarily. Oh, why? Look at the results of my survey below and you'll see.
Each view subclass in the Android system has the following three methods that are closely related to TouchEvent processing:
1) Public boolean dispatchtouchevent (motionevent ev) This method is used to distribute TouchEvent
2) Public boolean onintercepttouchevent (motionevent ev) This method is used to intercept touchevent
3) Public boolean ontouchevent (motionevent ev) This method is used to process touchevent when touchevent occurs, the activity first passes touchevent to the topmost view, TouchEvent first arrives at the topmost view of the dispatchtouchevent and is then distributed by the Dispatchtouchevent method, if Dispatchtouchevent returns True, The ontouchevent handle to this view, if Dispatchtouchevent returns false, give this view the Intercepttouchevent method to decide whether to intercept the event, if Intercepttouchevent returns True, that is, intercept, then give it to the ontouchevent to handle, if Intercepttouchevent return false, then passed to the child view, the Dispa Tchtouchevent again to begin the distribution of this event. If the event is passed to the ontouchevent of a child view of a layer, this method returns false, and the event is passed from this view to the ontouchevent to receive. If the ontouchevent passed to the top also returns false, the event "disappears" and the next event is not received.

Android screen Touch event mechanism (GO)

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.