zoukankan      html  css  js  c++  java
  • ViewGroup onInterceptTouchEvent,ViewGroup onTouchEvent,View onTouchEvent执行顺序说明

    今天抽出了一些时间实践了viewgroup和view的触摸事件顺序,之前也试过,总是忘记,今天记下笔记说明一下

    首先 onInterceptTouchEvent只会出现在viewgroup中,view中是没有此方法的。看下官方给出onInterceptTouchEvent返回值的解释

    Return true to steal motion events from the children and have

         * them dispatched to this ViewGroup through onTouchEvent().
         * The current target will receive an ACTION_CANCEL event, and no further
         * messages will be delivered here.

    意思大致上说如果返回true的话证明viewgroup消费了此手势的一系列事触摸事件(一般执行顺序 down,move,up),view 任何一个触摸事件都不会执行到ontouch方法中

    (注意此ontouch方法是子view的哦,并不是viewgroup的)

    1. onInterceptTouchEvent返回true

    当onInterceptTouchEvent 执行了down方法后,接下来的move,up等事件也不会通过此方法了,都会交给viewgroup的ontouch去处理。如果viewgroup的ontouch事件返回true 接下来的 move,up等事件也都被viewgroup 的ontouch方法拦截到,如果返回false的话,也就能拦截到down事件了。

    2.onInterceptTouchEvent返回false

     (1) 子View的onTouchEvent返回true
           ViewGroup的onInterceptTouchEvent和子view onTouchEvent会接收到接下来的所有消息
           ViewGroup的onTouchEvent不会接收到任何消息


     (2) 子View的onTouchEvent返回false 并且 ViewGroup的onTouchEvent返回false  执行结果如下:
            ViewGrouop onInterceptTouchEvent(13331): Action Down
    View onTouchEvent(13331): Action Down
    ViewGrouop onTouchEvent(13331): Action Down

     (3) 子View的onTouchEvent返回false 并且 ViewGroup的onTouchEvent返回true  执行结果如下:
            ViewGrouop onInterceptTouchEvent: Down
    View onTouchEvent: Down
    ViewGrouop  onTouchEvent: Down
    ViewGrouop  onTouchEvent: Move
    ViewGrouop  onTouchEvent: Up

    上述就是ViewGroup onInterceptTouchEvent,ViewGroup onTouchEvent,View onTouchEvent返回值不用所回调函数的顺序

  • 相关阅读:
    C#利用HttpWebRequest进行post请求的示例(HTTPS)
    以文件流的方式读取本地文件
    C#读取xml文件指定节点下的值
    C# get post 的方法
    SQL2008安装后激活方式以及提示评估期已过解决方法(转)
    python 左移右移 2个数交换
    python 循环内部添加多个条件判断会出现越界
    python __new__ __init__ __del__
    python 模块中__all__作用
    Python urllib的urlretrieve()函数解析 (显示下载进度)
  • 原文地址:https://www.cnblogs.com/riskyer/p/3400458.html
Copyright © 2011-2022 走看看