An explanation of the Android touch event delivery mechanism

Source: Internet
Author: User

Android-developed friends often deal with a variety of touch events, but in the process of touching events, there are three main methods: Dispatchtouchevent (), Onintercepttouchevent (), and ontouchevent (). Believe that this troubled a lot of friends, the following through the text to you about the transfer process between them.

Tools/Materials
    • Android
    • Android Studio
Method/Step
  1. 1

    The origin of the event:

    We all know that touch events start with the Dispatchtouchevent method of activity. The super.dispatchtouchevent (EV) of the parent class is called again, and the event is dispatched.

  2. 2

    ViewGroup vs. View: View is the simplest class for Android controls, and all controls inherit view directly or indirectly, that is, ViewGroup inherits view. View has two callback functions Dispatchtouchevent and Ontouchevent;viewgroup have three callback functions dispatchtouchevent, Ontouchevent and Onintercepttouchevent.

  3. 3

    Dispatchtouchevent Event Description:

    Dispatchtouchevent is only responsible for handling the distribution of touch events, which begins with the dispatchtouchevent of the activity. The parent class is then executed

    The Super.dispatchtouchevent (EV) event is distributed downward.

  4. 4

    Onintercepttouchevent Event Description:

    Onintercepttouchevent is a method provided by ViewGroup, which returns false by default to indicate that an event is not intercepted and when True indicates that the event was intercepted, which means that it handles consumption itself.

  5. 5

    Ontouchevent Event Description:

    ViewGroup and view have this method, ontouchevent this method mainly handles the touch event of the press move and bounce operation, when the return to true indicates consumption of this event, false is not consumed, that is, return to the previous layer of processing.

  6. 6

    The delivery process of the event:

    The delivery of events in Android is passed from the parent layout to the child layout, the parent layout can have many, that is, the process of Viewgroup-->viewgroup-->view, ViewGroup is a pass-through effect.

An explanation of the Android touch event delivery 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.