Research on the distribution mechanism of Android-----------events

Source: Internet
Author: User





Distribution mechanism for events:


1 The corresponding screen click event in Android will be distributed:
The screen and is calculated by the hardware to complete the physical coordinates. Generate an offset corresponding to the upper-left corner of your phone's screen!
Includes: Rawx Rawy


2 Setcontentview (R.layout.activity_main);

When a Click event occurs on the screen: Android will have the original click coordinates,
Sent to the Windows class. Windows (System-level Class) The phone's window, responsible for event delivery for the ancestors.
There is an instance of the Android system provided and only one window!

Window for the first time distribution event!

3Window passes events to its own child containers and components. The word content is Activity.


4 Activity is passed on to its own contentview. Check for Contentview content when passing
Whether the container or control is responding to an event.




The above: There is automatic generation of Android system, do not need our participation!
The basic principle.


----------------------------------------------------------------


The operation after 5 requires us (the engineer) to process:


6 Find the corresponding response event.
Depending on the physical coordinates, find the component of the response. Identify that container and component.

7 when the container finds the controls and containers that contain the handling events, the problem occurs when passing in X Y.
Coordinates are adjusted to their own X Y coordinates obtained with GetX and GetY!




8 distribution, within check to prevent? If an event is blocked, the event is not distributed down.
Onintercepttouchevent the parent container blocks the event distribution of subcomponents, and returns True if the subclass has no event distribution, and an event response!
Straight from the root!

Ontouchlistener ()
Returns true if it is not given to the parent class!



If Ontouchlistener first executes OnTouch ()
Return value true end of distribution
Returns False if the control itself is ontouchlistener.




---------------------------------------------------------------


1 Default: How do I get a control to accept MOVE up?
Down is the first, and if true, the event is not distributed. Or not!


2 Click in general, there is a view of the ontouchevent departure.


3 Long Press drag and more gesture events. Can have a gesture recognizer to detect, to handle the event!


4 If the event is triggered, it should be handled according to the functionality of the current control, where the function of the parent class needs to be used.
The event-handling mechanism of the parent class should be called for processing.

Example: ListView ontouchevent ()

5 Delivery of events: Not a subclass is associated with a parent class.
IsThe relationship between the parent container and the child controls.














Research on the distribution mechanism of Android-----------events

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.