Android event delivery mechanism and onintercepttouchevent () and Ontouchevent () Two Secrets and leadership stories

Source: Internet
Author: User

The summary is not very good, oneself also a bit do not understand, just now use, research A, again summary, convenient everybody view

General:

What does it mean to have a intercept in 1.onInterceptTouchEvent? She called the interception, you probably know that she function, she is your kiss little secretary, what matter, first find the secretary, secretary to decide whether you personally deal with it, since it is secretary, is not everyone can have it? Of course not, this secretary is only ViewGroup, so only inherit the ViewGroup control only, those TextView ah button ah what, there must be no, why? Because he is not enough (inherited from the view), there is no secretary drop, note that if the leadership decided to go, then the notice after that level does not go through the small secret, direct hair leadership.

2. The order in which events are passed, in turn, occurs when action_down from the parent control to the child control, then Action_move (which may or may not appear), and finally Action_up, which is to be transferred sequentially from the parent control to the child control, on the phone action_ Move and Action_up basically will appear, is because the cell phone sensor is very sensitive, but the simulator is not the same, if there is no sliding, there will be no action_move, all events, Action_down, Action_move and Action_ Up is first sent from the root control (the outermost layer in the layout file) Onintercepttouchevent, that is, each control first receives the Onintercepttouchevent event (you must, of course, have this ability to receive, the reason to see above)

3. There is a small secret, there is an incident, that should have the leadership, Ontouchevent is the leader, is to deal with specific events, the leadership will first receive the small secret hair of the Action_down incident, the leadership of a look, (1) Wow, the small secret sent to, hurriedly see, the evening is not what activities, a look, There are really activities, but also with the small secret to go out high, enjoyable, tell the small secret (return true), participate in the evening activities, then the superior conclave then to the activities of the specific arrangements (Action_move and ACTION_UP) also sent over, are handled by this leader (note, Specific activities are superior to the direct notification of the subordinate leadership (Ontouchevent), here no longer need to subordinate small secret filter, because the small secret dress up, evening to accompany the leadership activities it), other leaders, can only feel powerless

(2) If the leader looked, found not to go out happy things, the mood depressed, and can not with the small secret together, this Nima, but also to a Mao Ah! Don't go!!! Tell the Secret (return false) not to handle, then the secret will report to the superior (parent control), and then be handled by the superior leader. God horse? The superior leader does not handle, depends on, that all right, all to their ancestors (view) to go, view the view source code, you will find, like, if accepts the event, returns True, then handles Action_move and action_up, does not handle, returns false, to the ancestor this level, If no one has to deal with it, there is no way, the incident disappeared, ready to deal with the next

<?xml version= "1.0" encoding= "Utf-8"? ><com.touchstudy.layoutview1 xmlns:android= "/http Schemas.android.com/apk/res/android "    android:orientation=" vertical "    android:layout_width=" Fill_parent "    android:layout_height= "Fill_parent" >    <com.touchstudy.layoutview2        android:orientation= " Vertical "        android:layout_width=" fill_parent "        android:layout_height=" fill_parent "        android:gravity=" Center ">       <com.touchstudy.mytextview             android:layout_width=" wrap_content "            android:layout_ height= "Wrap_content"            android:id= "@+id/tv"            android:text= "AB"            android:textsize= "40SP"            Android:textstyle= "Bold"            android:background= "#FFFFFF"            android:textcolor= "#0000FF"/>   </ Com.touchstudy.layoutview2></com.touchstudy.layoutview1>

Analysis One: On the above layout, analysis, if not interfere with their respective methods of the return value, first is the root control LayoutView1 Secretary 1 (onintercepttouchevent) received notice (Action_down), she was thinking, Ah, Do you want to notify the root control of the leader 1 (ontouchevent), well, forget it, so important leadership 1, too busy, masterful ah, first down notice it, see if there is a response, and then directly to LAYOUTVIEW2 Secretary 2, Secretary 2 want to accompany the leader 2 too tired, Want to rest, do not tell him, and then directly issued Mytextview Leadership 3, the leadership of the 3 level not enough Ah, no small secret ah, what to do, and then deal with the notice, he thought ah, want to go? Really tangled, he gave himself two paths:

1. Go, return True, good, this level of return, all know that he is going to, it is easy, the event arrangement (Action_move and ACTION_UP) came, Secretary 1 directly notify the Secretary 2 (why not directly inform the leader 3, because he busy leader 3 too ugly, haha, Joking drops, the leader was absolutely handsome and dashing, suave ..., because not enough level let oneself to notice AH), Secretary 2 received notice, and then directly issued to the leadership 3, and then lead 3 on happy went, so say Ah, this management is very strict drop, first level down distribution, you subordinate thing, above all know, must be careful ...

2. Do not go, return false, alas, do not bother to report to the superior, his illness, Secretary 21 Listen, alas, no way, this only notice home Leadership 2, Wake Leader 2, ask him to go, leadership 2 just rest good, good mood, laugh a wave, go, well, to the above report, Secretary 1 of the notice came, Some people asked whether the Secretary 2 over again, the answer is, because the Secretary 2 Filter once, is decided to inform the leadership (it seems that the leadership must be good relations with the small secret, or the key moment to you come, you are finished), once the leader has been notified, the Secretary will be no matter, the secretary did go, the Secretary dressed up , the evening to accompany the leadership ah, not dress the beautiful point, this is not to the leadership shameful?

Take a look at the picture

Analysis of two

If you put LayoutView2 's onintercepttouchevent back to True will God horse condition?

In front of the analysis, here only a little, since the leadership of the 2 of the Secretary to inform the leadership, the leadership also decided to go, then you will not lead 3 what matter, the leader 3 what can not receive, online said will be received action_cancel, I did not measure, I think it should be nothing to receive, because Action_ Cacel precondition is that you received the Action_down, and in the later time, the superior leader suddenly again to intervene in this matter, (in Onintercepttouchevent action_move/up return true, truncated) this time, will notify the subordinate to cancel this event, when will encounter this situation, when the ListView sliding, press and hold the screen to swipe up, if the program simulation, is in the onintercepttouchevent of the upper level of control Action_ When down, return False (passed to the subordinate), and then return Tue at ACTION_UP, truncate the subsequent message, this situation will receive action_cancel

Well, to this end, it's time to take a bath, about the specific screen click event processing mechanism and process in the future blog post finishing! Thank you!

Finally attach source address: Http://files.cnblogs.com/xiaoQLu/MotionEventTest.rar

Android event delivery mechanism and onintercepttouchevent () and Ontouchevent () Two Secrets and leadership stories

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.