Android touch event

本文深入探讨了Android系统中触摸事件的处理机制,包括事件的分组、优先级处理和事件传递规则,帮助开发者更好地理解和优化应用的触摸交互体验。
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.

转载于:https://my.oschina.net/jerikc/blog/123013

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值