Touch分发 demo打印
标签(空格分隔): 点击事件
1、测试布局
父view:
- button :测试点击事件
- 自定义button:打印 dispatchTouchEvent 和onTouchEvent
- edittext: 测试是否可以获取焦点
- yellowRela:是否和button的效果一样
- maskRela:最外面的子view 如何影响底下的view
- buttonRela 两个button的父View
- clickRela 在最底部监听事件是否能到达
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>
<com.linewow.xhyy.dispatcherdemo2.ClickRela
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_click"/>
<com.linewow.xhyy.dispatcherdemo2.RedRela
android:id="@+id/main_rela"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00">
<com.linewow.xhyy.dispatcherdemo2.ButtonRela
android:layout_width="match_parent"
android:id="@+id/main_button_rela"
android:layout_height="wrap_content">
<Button
android:id="@+id/main_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<com.linewow.xhyy.dispatcherdemo2.GreenButton
android:id="@+id/main_green_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/main_btn"
android:background="#32CD32"
android:text="greenbutton"
android:textColor="#fff" />
</com.linewow.xhyy.dispatcherdemo2.ButtonRela>
<EditText
android:id="@+id/main_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/main_button_rela"
android:background="#fff" />
<com.linewow.xhyy.dispatcherdemo2.YellowRela
android:id="@+id/main_dis_rela"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/main_edit"
android:background="#ff0"></com.linewow.xhyy.dispatcherdemo2.YellowRela>
<com.linewow.xhyy.dispatcherdemo2.MaskRela
android:id="@+id/main_rela2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="200dp"></com.linewow.xhyy.dispatcherdemo2.MaskRela>
</com.linewow.xhyy.dispatcherdemo2.RedRela>
</RelativeLayout>
Part 1.先看mask和yellow之间的关系
1、mask不做任何处理:
点击空白
12-02 14:21:11.356 32004-32004/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 14:21:11.356 32004-32004/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 14:21:11.356 32004-32004/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onTouchEvent(ev)
点击mask
12-02 14:24:31.996 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 14:24:31.996 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 14:24:32.006 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 14:24:32.006 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask onInterceptTouchEvent
12-02 14:24:32.006 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask onTouchEvent
12-02 14:24:32.006 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onTouchEvent(ev)
事件的回传
点击yellow
12-02 14:25:04.196 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 14:25:04.196 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 14:25:04.196 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 14:25:04.196 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask onInterceptTouchEvent
12-02 14:25:04.196 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask onTouchEvent
12-02 14:25:04.196 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: yellow dispatchTouchEvent拦截了
12-02 14:25:04.206 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: yellow onInterceptTouchEvent
12-02 14:25:04.206 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: yellow onTouchEvent
12-02 14:25:04.206 6263-6263/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onTouchEvent(ev)
yellow dispatchTouchEvent true
12-02 14:32:55.846 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 14:32:55.846 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 14:32:55.846 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 14:32:55.846 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask onInterceptTouchEvent
12-02 14:32:55.846 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask onTouchEvent
12-02 14:32:55.846 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: yellow dispatchTouchEvent拦截了
12-02 14:32:55.896 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 14:32:55.896 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 14:32:55.906 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: yellow dispatchTouchEvent拦截了
这时不会走yellow其他方法了 up和down
yellow dispathcTouchEvent false
12-02 14:34:20.396 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 14:34:20.396 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 14:34:20.396 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 14:34:20.396 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask onInterceptTouchEvent
12-02 14:34:20.406 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask onTouchEvent
12-02 14:34:20.406 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: yellow dispatchTouchEvent拦截了
12-02 14:34:20.406 13275-13275/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onTouchEvent(ev)
这时不会走yellow其他方法了 只有down
2、mask dispatchTouchEvent 处理
1 、 true 任何有mask的区域:
12-02 14:28:44.366 8422-8422/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 14:28:44.366 8422-8422/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 14:28:44.366 8422-8422/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 14:28:44.466 8422-8422/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 14:28:44.466 8422-8422/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 14:28:44.466 8422-8422/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
edittext 不会再弹出键盘
2、false
false只有mask的部分
12-02 14:45:31.996 23041-23041/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 14:45:31.996 23041-23041/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 14:45:31.996 23041-23041/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 14:45:31.996 23041-23041/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onTouchEvent(ev)
和yellow是一致的 直接父类ontouch
false yellow部分
12-02 14:46:57.376 23041-23041/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 14:46:57.376 23041-23041/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 14:46:57.376 23041-23041/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 14:46:57.376 23041-23041/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: yellow dispatchTouchEvent拦截了
12-02 14:46:57.376 23041-23041/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: yellow onInterceptTouchEvent
12-02 14:46:57.376 23041-23041/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: yellow onTouchEvent
12-02 14:46:57.376 23041-23041/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onTouchEvent(ev)
上下次序是不会变的 yellow肯定会晚于mask执行
Part 2.ButtonRela和ClickRela 之间的关系
(相当于对yellow加了子类,这里mask都为dispatchTouchEvent false)
点击buttonRela以外的部分
mask外
12-02 15:11:55.696 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 15:11:55.696 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 15:11:55.696 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onTouchEvent(ev)
12-02 15:11:55.776 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: bottom click
mask上
12-02 15:12:43.856 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 15:12:43.856 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 15:12:43.856 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 15:12:43.856 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onTouchEvent(ev)
12-02 15:12:43.926 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: bottom click
yellow上
12-02 15:13:39.896 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 15:13:39.896 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 15:13:39.896 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 15:13:39.896 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: yellow dispatchTouchEvent拦截了
12-02 15:13:39.896 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: yellow onInterceptTouchEvent
12-02 15:13:39.896 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: yellow onTouchEvent
12-02 15:13:39.896 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onTouchEvent(ev)
12-02 15:13:39.986 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: bottom click
Clickrela 都能接收到监听
点击普通Button
12-02 15:15:41.566 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 15:15:41.566 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 15:15:41.566 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 15:15:41.566 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
12-02 15:15:41.566 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela onInterceptTouchEvent
12-02 15:15:41.636 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 15:15:41.636 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 15:15:41.646 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
12-02 15:15:41.646 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela onInterceptTouchEvent
12-02 15:15:41.646 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: button点击了
button 消耗掉了事件 不会出现父view ouTouch的回传了
点击greenbutton (不做任何处理)
12-02 15:19:09.376 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 15:19:09.376 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 15:19:09.376 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 15:19:09.386 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
12-02 15:19:09.386 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela onInterceptTouchEvent
12-02 15:19:09.386 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: GreenButton dispatchTouchEvent
12-02 15:19:09.386 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: GreenButton onTouchEvent
12-02 15:19:09.456 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 15:19:09.456 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 15:19:09.456 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
12-02 15:19:09.456 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela onInterceptTouchEvent
12-02 15:19:09.456 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: GreenButton dispatchTouchEvent
12-02 15:19:09.456 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: GreenButton onTouchEvent
12-02 15:19:09.456 14507-14507/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: GreenButton点击了
手势的up和down 所以走了两遍
点击greenbutton (dispatchTouchEvent false)
经过上面的总结 猜测 返回false则穿透
12-02 15:25:51.136 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 15:25:51.136 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 15:25:51.136 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 15:25:51.136 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
12-02 15:25:51.136 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela onInterceptTouchEvent
12-02 15:25:51.136 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: GreenButton dispatchTouchEvent
12-02 15:25:51.136 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela onTouchEvent
12-02 15:25:51.136 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onTouchEvent(ev)
12-02 15:25:51.186 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: bottom click
点击greenbutton (dispatchTouchEvent true)
12-02 15:31:06.346 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 15:31:06.346 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 15:31:06.346 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 15:31:06.346 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
12-02 15:31:06.346 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela onInterceptTouchEvent
12-02 15:31:06.346 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: GreenButton dispatchTouchEvent
12-02 15:31:06.416 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 15:31:06.416 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 15:31:06.416 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
12-02 15:31:06.416 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela onInterceptTouchEvent
12-02 15:31:06.426 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: GreenButton dispatchTouchEvent
事件的up和down 走了两遍 touch事件不会执行 ,自己监听不到, 底部也监听不到(事件去哪了?)(这时up时mask也不会再执行了 因为返回了false)
点击greenbutton (onTouchEvent true)
12-02 15:36:22.676 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 15:36:22.676 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 15:36:22.686 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 15:36:22.686 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
12-02 15:36:22.686 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela onInterceptTouchEvent
12-02 15:36:22.686 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: GreenButton dispatchTouchEvent
12-02 15:36:22.686 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: GreenButton onTouchEvent
12-02 15:36:22.776 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 15:36:22.776 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 15:36:22.776 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
12-02 15:36:22.776 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela onInterceptTouchEvent
12-02 15:36:22.776 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: GreenButton dispatchTouchEvent
12-02 15:36:22.776 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: GreenButton onTouchEvent
事件的up和down onClick 不会执行了 顺序同上述的viewgroup是一样的 底部也监听不到
点击greenbutton (onTouchEvent false)
12-02 15:38:33.356 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-02 15:38:33.356 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-02 15:38:33.356 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-02 15:38:33.356 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
12-02 15:38:33.356 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela onInterceptTouchEvent
12-02 15:38:33.356 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: GreenButton dispatchTouchEvent
12-02 15:38:33.356 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: GreenButton onTouchEvent
12-02 15:38:33.356 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela onTouchEvent
12-02 15:38:33.356 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onTouchEvent(ev)
12-02 15:38:33.436 31200-31200/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: bottom click
只有down没有 up onclick不会执行了 自己监听不到 底部可以监听到了
Part 3.ButtonRela和Button之间的关系
测试父级dispatch 对子级的影响
ButtonRela dispatche返回false
12-06 19:46:10.254 20268-20268/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-06 19:46:10.254 20268-20268/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-06 19:46:10.254 20268-20268/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-06 19:46:10.254 20268-20268/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
12-06 19:46:10.254 20268-20268/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onTouchEvent(ev)
12-06 19:46:10.334 20268-20268/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: bottom click
直接拦截了 不会传递给子类了 和maskRela的是一样的
ButtonRela dispatche返回
12-06 19:48:41.694 29453-29453/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-06 19:48:41.694 29453-29453/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-06 19:48:41.694 29453-29453/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: mask dispatchTouchEvent拦截了
12-06 19:48:41.694 29453-29453/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
12-06 19:48:41.714 29453-29453/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-06 19:48:41.714 29453-29453/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-06 19:48:41.714 29453-29453/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
12-06 19:48:41.784 29453-29453/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-06 19:48:41.784 29453-29453/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-06 19:48:41.784 29453-29453/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
12-06 19:48:41.794 29453-29453/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.dispatchTouchEvent(ev)
12-06 19:48:41.794 29453-29453/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: 父view:super.onInterceptTouchEvent(ev)
12-06 19:48:41.794 29453-29453/com.linewow.xhyy.dispatcherdemo2 E/MainActivity: ButtonRela dispatchTouchEvent拦截了
同样不会传递给子类 重复的次数取决于 motionevent的次数
所以dispatche返回true表示事件被当前视图消耗掉了 所以不会继续分发了 连续的打印则是事件的不断进入
2、总结
dispatchTouchEvent决定了兄弟直接的拦截
onInterceptTouchEvent 决定了父子之间的拦截