Preface:

Read a few days finally before the 5.0 version of the event distribution source code combined with the blog general idea comb almost. I didn’t read the fine print. Too much! , blog combined with the source code recommended to see several times!! I saw the beginning of the time is also meng state, see a few times much better. As for the new version of the event distribution source more difficult to see the head or confused. Originally wanted to see the end of their own writing analysis, but the following quote of the blog tycoon to write is too sweet, there is no need to write their own, after all, the purpose of writing blog is to absorb! Rather than trying to be a copycat, which also delays the reader.

purpose

Since there are events distributed, it must be dealing with a real scene, otherwise even if the writing is awesome! Without the actual scene, the significance would be greatly compromised. So the actual scene is that there are various events sliding conflict in our development, if not dealt with, the experience will be very poor!

1. What are the event sliding conflict scenarios? And how to resolve sliding conflicts?

Internal interception, external interception. Reference 1: common slide conflict scenarios and solutions reference 2: a solution to the Android View slide conflict these two articles, in fact, and deal with the event conflict, basically is the last essence of the. If only two articles are required to handle conflicts, it is enough. However, if we do not understand the event distribution mechanism, we are not clear how this can handle sliding conflicts, the whole mechanism of the event is confused, so the core of the analysis of the event distribution mechanism

2. Event distribution mechanism

Event distribution source code to see a huge pain, especially the new version, which is particularly detailed. Originally wanted to refine it, such as 1. Event distribution essence: is the click event (MotionEvent) to a specific view& the whole process of processing. The core method involved in event distribution :dispatchTouchEvent()(first called) OnInterceptTouchEvent (), onInterceptTouchEvent()(viewGroup only), onTouchEvent()(Whether the current view handles the event, returns true, otherwise passes to the parent class), and extend onTouch and onClick 3. Between which objects are events passed? Activity -> ViewGroup -> View 4. What methods are used to coordinate the event distribution process? DispatchTouchEvent (), onInterceptTouchEvent() and onTouchEvent(). Action_down returns false when action_down returns false when action_down returns false when action_down returns false when action_down returns false when action_down returns false Android event distribution mechanism Strategy, you deserve the new version reference (harder) : [a simple Android event dispatch mechanism: the most comprehensive and easy to understand: senior (3) of article] (www.jianshu.com/p/e57372c0b)…

Added: Why does viewpager not have sliding collisions? How is the source code handled?

ViewPager source code analysis (2) : sliding and conflict processing, the core point is actually based on horizontal/vertical movement distance, and the Angle of movement to determine who to deal with