Android touch event is different from other system. In common system, every touch event (DOWN, MOVE, UP) is separated event. But in Android, they are managed a DOWN, several MOVE, and a UP as a group.

Here is the rules:

  1. DOWN is the first event to be handled. The one who handles the DOWN will handle all the events in this group.
  2. The *handle* means the onTouchEvent function of this View returns true.
  3. The View who returned false will never handle the other event in this group again, never!
  4. The order of the event processing is: child, parent.
  5. Only the DOWN may be handled by more than one View, others must be handled only once.
  6. When the next DOWN occurs, there is a new group creates, and the current group ends.

And when there is a ViewGroup and a View, and the View is the child of the ViewGroup, then the VIewGroup has priority to choose which one can handle this group of events. That is the onInterceptTouchEvent function.

The onInterceptTouchEvent function is the most first handler of the DOWN event. If returns true, then all the events in this group will be handled by ViewGroup, and the child will know nothing happen ;(

If onInterceptTouchEvent returns false, then DOWN will be handled firstly by child then by parent. That is the normal order.

Once onInterceptTouchEvent returns true, then this function will not be involved again, and all the next events will be passed to parent.

If onInterceptTouchEvent returns fasle, then every following event will firstly handled by this one, then pass to the child.

Note that onInterceptTouchEvent function is for dispatching touch events to children. So if the onInterceptTouchEvent retuyrns false and on child handles that event, the parent will handle it by onTouchEvent. If onTouchEvent returns true, then from that on, all the touch events in that group will directly dispatched to onTouchEvent. If onTouchEvent returns false, then no event will dispatch to the parent again.

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 开关飞行模式
  2. android 启动自动调用自己创建的脚本(应用
  3. Android——高德地图地点搜索框
  4. Android(安卓)拷贝Asset目录下文件或者文
  5. ColorStateList按钮文字变色
  6. android 加载时闪烁点样式的启动画面
  7. AcitonBar自定义布局
  8. Android入门:布局介绍
  9. Android(安卓)调用另一个应用(app)中的Acti
  10. Android(安卓)SDK 2.3与Eclipse最新版开