Delivery and delivery of Android touch events

Source: Internet
Author: User

1. Touch events are distributed from activity to layer

Always distributed to the focus control for processing

2. If the control's event-handling method returns True

The control consumes and continues to follow this event

Otherwise, the event is passed to the previous layer container of the control

3. The Ontouch method of the control's touch listener precedes

Ontouchevent execution of the control itself


How touch events are distributed and processed

Dispatchtouchevent

Onintercepttouchevent (only ViewGroup has this interception method)

Ontouchlistener.ontouch

Ontouchevent


Suppose an activity contains only one linearlayout, and this linearlayout contains a textview. As you can see from log,

When the user presses this textview, the order of the functions executed is:

Activity.dispatchtouchevent

Linearlayout.dispatchtouchevent

Linearlayout.onintercepttouchevent (LinearLayout is ViewGroup)

Textview.dispatchtouchevent

TextView.onTouchListener.onTouch

Textview.ontouchevent

LinearLayout.onTouchListener.onTouch

Linearlayout.ontouchevent

And finally the activity.ontouchevent.

The above is the case where each layer does not consume this touch event, that is, all methods return FALSE.

If either method consumes this event, it returns True, in which case the event is only to this method and the subsequent methods do not. Subsequent events will also be executed only to this method, that is, this method consumes and continues to pay attention to this event, such as: Move and lift, and other subsequent events.


Delivery and delivery of Android touch events

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.