Touch分发 demo打印

Touch分发 demo打印

标签(空格分隔): 点击事件


1、测试布局

父view:

  • button :测试点击事件
  • 自定义button:打印 dispatchTouchEvent 和onTouchEvent
  • edittext: 测试是否可以获取焦点
  • yellowRela:是否和button的效果一样
  • maskRela:最外面的子view 如何影响底下的view
  • buttonRela 两个button的父View
  • clickRela 在最底部监听事件是否能到达
device-2016-11-25-113819.png

    <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 决定了父子之间的拦截

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,186评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,858评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,620评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,888评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,009评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,149评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,204评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,956评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,385评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,698评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,863评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,544评论 4 335
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,185评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,899评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,141评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,684评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,750评论 2 351

推荐阅读更多精彩内容