view的onInterceptTouchEvent 方法

Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.

实现这个方法能够拦截所有的屏幕触摸事件,允许每个节点在事件分发给子view时查看事件,并且拥有当前手势的所有权

Using this function takes some care, as it has a fairly complicated interaction with View.onTouchEvent(MotionEvent), and using it requires implementing that method as well as this one in the correct way. Events will be received in the following order:

使用这个功能要非常小心,因为这个方法和View.onTouchEvent(MotionEvent)有相当复杂的影响,使用这个方法要求必须正确实现这两个方法。事件按照下面的流程被接收:

  1. You will receive the down event here.

    首先会在这里接收到down 事件

  2.    The down event will be handled either by a child of this view group, or given to your own onTouchEvent() method to handle; this means you should implement onTouchEvent() to return true, so you will continue to see the rest of the gesture (instead of looking for a parent view to handle it). Also, by returning true from onTouchEvent(), you will not receive any following events in onInterceptTouchEvent() and all touch processing must happen in onTouchEvent() like normal.

          一个down事件可以被view group的子控件处理,或者view group自己处理。意思是,如果你实现了一个 onTouchEvent()并且返回了true,那么你将看到下面的手势(而不是继续寻找一个父控件来处理这个事件)。同时,如果你从onTouchEvent()中返回了一个true,onInterceptTouchEvent()中将不会再收到任何接下来的事件,所有的触屏处理都将在onTouchEvent()。

3.    For as long as you return false from this function, each following event (up to and including the final up) will be delivered first here and then to the target's onTouchEvent().

      如果在在这个方法中返回了false,接下来的所有事件(包含直到up)将被先传递到这然后在到目标的onTouchEvent().

4.   If you return true from here, you will not receive any following events: the target view will receive the same event but with the action ACTION_CANCEL, and all further events will be delivered to your onTouchEvent() method and no longer appear here.

     如果在这返回了一个ture,你将不会再收到接下来的任何事件:目标view会接收到同一个事件,action却是ACTION_CANCEL,,而且所有后续的事件将会被传递到这个view的onTouchEvent()方法中处理,不会再出现在这儿。

 

-------------------------------------------------------------------------------

推荐一篇好文章:http://www.blogjava.net/TiGERTiAN/archive/2011/02/22/344869.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值