Three events in the basic action sequence of message distribution knowledge
Touchevent has three types of events: down, move, and up.
Among them, the move event may occur multiple times in an operation (here, an operation is the interaction between the user and the screen, that is, the sequence of actions from down to up.
However, we believe that an action sequence will contain the above three events. Therefore, in event processing, we must handle this process well, and the most important thing is down events, this is the starting point of an action sequence. If it is not down, the subsequent events will not be discussed.
Therefore, we regard the classes that consume down events as the final carrier of this action sequence.
If the down event is not handled by you, move and up of the action sequence will not be handled by you.
Their trigger order is as follows:
Action_down-> action_move...-> action_move-> action_up
Message distribution process from parent to child
The distribution process of Android message queue is
Activity-> viewgroup1-> viewgroup1 direct sub-viewgroup-> ×××××-> leaf View
One-to-one correspondence between messages and Processing
One message. By default, only one control is required for processing messages. The intermediate message channels only serve as intermediate messages, and are not processed. If the processing is complete, the system returns the result without notifying the intermediate step.
If you want to process a message with multiple controls, you need to modify the logic here.
Message Processing Process, from child to parent
If the message is always returned, false is returned.
It is processed in sequence from child to parent. No one can be processed, or true is returned so far.
For example:
If an activity calls a view, the ontouchevent (motionevent event) in the view is first executed. If false is returned,
Then execute ontouchevent (motionevent event) in the activity ),
Otherwise, the ontouchevent (motionevent event) in the activity is not executed );
However, when you touch the title bar of the screen, the ontouchevent (motionevent event) in the activity is executed ).
Android event distribution processing policy
The distribution process of activity and view controls is different. First, we will introduce the distribution process of viewgroup.
Android viewgroup distribution and processing principles
- By default, one message only needs to be processed by one person at the end, and other message channels only have the effect of intermediate transmission.
- Three-level mechanism for message transmission:
- Dispatchtouchevent ),
- Whether the decision is distributed to the lower-level or the onintercepttouchevent ),
- Processing logic (ontouchevent, ontouch, onclick, onlongclick, etc)
- View internal processing logic order, in sequence: (Note: when return is not true)
- Ontouchevent
- Onclick
- Onlongclick
- Differences between ontouchlistener and ontouch ontouchevent
- First, execute ontouch in ontouchlistener (), and then execute the overwritten ontouchevent (motionevent ). (Note: when return is not true)
- Ontouch () is used by users of the view to get touch events while ontouchevent () is used by Derived classes of the view to get touch events.
- More detailed can see http://blog.csdn.net/ddna/article/details/5451722
- In message processing, return true indicates that the message is completely processed, and other events are not used for subsequent processing.
Distribution processing logic of view and viewgroup
|
Accept messages sent from superiors The external call interface of the abstract object. For external users, only this interface is known, and others are unknown. It is equivalent to an enterprise guard. The Postman gives the email to the guard.1. Return Value: false Do not accept subsequent events in the action sequence Generally, there are three types of events: down, move, and up false, which indicate that subsequent events in the action sequence are not accepted. Therefore, this subsequent operation does not take effect. For example, if the event is down, false is returned, both the move and up operations are not accepted. Only the next action can be accepted. 2. Return Value: True Continue to accept subsequent events in the action sequence, such as move and up
If super. dispatchtouchevent is called. In this way, the onintercepttouchevent will continue to be called. If the returned value is super. dispatchtouchevent, it means that the onintercepttouchevent determines the event flow, The return value of super. dispatchtouchevent is the default value. By default, the system only has one control to process the message. If you need to process multiple controls at the same time, you must return true and call Super. dispatchtouchevent. |
|
Abstract The Internal interface of the object. Rather than the internal staff of the company, the company is responsible for distributing letters. However, once the down event of the action sequence knows how to distribute it, it will be bypassed next time.Return Value: True Process it by yourself. You do not need to continue downloading. The event is passed to your ontouchevent () If the down event returns true after onintercepttouchevent (), it is passed to ontouchevent, When true is returned, subsequent events of the action sequence are not passed through onintercepttouchevent, but directly transmitted to ontouchevent in dispatchtouchevent. Return Value: false You cannot completely process it yourself, or you cannot process it. The dispatchtouchevent () passed to the next view () Onintercepttouchevent returns false, which should be passed to the dispatchtouchevent of the next sub-view. However, if the view of the clicked leaf node does not exist, the sub-view is directly sent to its own ontouchevent. Onintercepttouchevent is to determine the subview to which the event is passed. If false is returned, no subview is processed (because no subview is clicked, the subsequent events processed in ontouchevent do not have to pass through onintercepttouchevent. it judges that the events are passed to the sub-view and are not processed by the sub-view. |
- Ontouchevent
- Onclick of view. onclicklistener
- Onlongclick of view. onlongclicklistener
- Ontouch of view. ontouchclicklistener
|
Specific officer's There is a sequence. If you finish this task by working first, it will not be passed on.If onclick, onlongclick, and ontouchevent are overwritten in a view, ontouchevent first captures action_down and action_up events, and then triggers onclick or onlongclick. The returned values true and false indicate whether the event is consumed, If it is consumed, it will not be passed to other controls. If it is not consumed, it will be passed to other controls to trigger the event processing functions of other controls. |
References
Call mechanisms of Android ontouchevent, onclick, and onlongclick
Http://blog.csdn.net/ddna/article/details/5451722
Android event processing
Http://blog.csdn.net/leesidong/article/details/6973261
Android framework -- touch event dispatching process
Http://blog.csdn.net/stonecao/article/details/6759189
Processing logic of touch events in Android
Http://www.oschina.net/question/163910_27289