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)有相当复杂的影响,使用这个方法要求必须正确实现这两个方法。事件按照下面的流程被接收:
- 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