The difference between Android OnTouch () and Ontouchevent ()

Source: Internet
Author: User

1.onTouch Method:
The Ontouch method is the method defined in the Ontouchlistener pretext of view.
When a view is bound to a ontouchlister, the Ontouch method is called when a touch event is triggered.
(When the handle is placed on the view, the Ontouch method is called over and over again)


2.onTouchEvent Method:
The Ontouchevent method is the method of the override activity.
Once the activity's Ontouchevent method is re-used, this method is not invoked when the screen has a touch event.
(When the handle is placed on the activity, the Ontouchevent method is invoked over and over again)


Delivery of 3.touch Events:
Put a TextView instance TV in an activity, and the TV's property is set to Fill_parent
In this case, when the hand is placed on the screen, the first is the TV response to the touch event, which executes the Ontouch method.


If the Ontouch return value is true,
Indicates that the touch event is handled by the Ontouch method and does not pass the touch event back to the activity.
This means that the Ontouchevent method is not called.
(When the hand is placed on the screen, the Ontouch method is called over and over again)


If the return value of Ontouch is false,
Indicates that the touch event was not fully processed by the TV, and Ontouch returned, the touch event was passed to the activity,
The Ontouchevent method is called.
(When the handle is placed on the screen, the Ontouch method is called once, and the Ontouchevent method is invoked over and over again)

The difference between Android OnTouch () and ontouchevent ()

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.