事件分发,滑动冲突

事件逐层分发,判断是否拦截,拦截就本层消费,否则向下分发,直至被消费。

1. 事件分发过程的理解

1.1. 概述

事件主要有 down (MotionEvent.ACTION_DOWN),moveMotionEvent.ACTION_MOVE),upMotionEvent.ACTION_UP)。
基本上的手势均由 down 事件为起点,up 事件为终点,中间可能会有一定数量的 move 事件。这三种事件是大部分手势动作的基础。

事件和相关信息(比如坐标)封装成 MotionEvent

大体的分发过程为:

首先传递到 Activity

然后传给了 Activity 依附的 Window

接着由 Window 传给视图的顶层 View 也就是 DecorView  Decor(装饰)

最后由 DecorView 向整个 ViewTree 分发。

分发还会有回溯的过程。最后还会回到 Activity 的调用中。

Activity 的分发事件源码

public boolean dispatc

猜你喜欢

转载自blog.csdn.net/qq_38998213/article/details/105053364