onInterceptTouchEvent / onTouchEvent响应事件的详析

onInterceptTouchEvent(),onTouchEvent() 默认返回false

注:事件分发机制是由 dispatchTouchEvent() 开始分发的

onInterceptTouchEvent()

ACTION_DOWN ------------ return true: ---→  将事件传递给该view下的 onTouchEvent()                                                                                                                                                                                                                                                                                                                          ACTION_MOVE ACTION_UP 都将直接由 onTouchEvent() 响应                                                                      

                                                                        该view的 onInterceptTouchEvent() 将无法响应 ACTION_MOVE,ACTION_UP

                            ------------ return false:    ↓   将事件向下传递(判断是否存在下级)

                                                              无下级: 将事件传递给该view下的 onTouchEvent()(等同于返回true)

                                                              有下级: 判断下一级是View 还是 ViewGroup

                                                                           ViewGroup : 将事件传递给下一级的 onInterceptTouchEvent(),一直向下传递

                                                                           View: 将事件传递给下一级的 onTouchEvent()

                                                               ACTION_MOVE ,ACTION_UP 都将由第一级别的 onInterceptTouchEvent() 响应

                                                                                              return false: 将ACTION_MOVE 事件传递给下一级的 onInterceptTouchEvent() ,以此类推

                                                                                              return true:   将ACTION_CANCEL 事件传递给 下面级别的所有响应 ACTION_DOWN 事件的方法,

                                                                                                                  将ACTION_MOVE 事件传递给此view 的onTouchEvent() ,所以接下来的action(ACTION_MOVE,ACTION_UP)都将按照这个顺序传递

onTouchEvent()

ACTION_DOWN ------------- return true: ---→  判断是否存在上级

                                                               无上级:将事件传递给下面的action(响应 ACTION_MOVE,ACTION_UP)

                          ACTION_MOVE,ACTION_UP: 将直接由 onTouchEvent() 响应

                                                               有上级:将事件传递给 第一级 onInterceptTouchEvent() 来响应 ACTION_MOVE,ACTION_UP 事件

                                                                             第一级的onInterceptTouchEvent() 响应了ACTION_MOVE 事件后 

                                                                                                                 return false: 将ACTION_MOVE 事件传递给下一级的 onInterceptTouchEvent() ,以此类推

                                                                                                                 return true:   将ACTION_CANCEL 事件传递给 下面级别的所有响应 ACTION_DOWN 事件的方法

                                                                                                                                      将ACTION_MOVE 事件传递给此view 的onTouchEvent() ,所以接下来的action(ACTION_MOVE,ACTION_UP)都将按照这个顺序传递

                                                                                                                                   

                            ------------- return false:    ↑    将事件向上传递(判断是否存在上级)

                                                               无上级:事件终止  X

                                                               有上级:事件传递给上一级的 onTouchEvent()

 

onTouchEvent()

posted @ 2016-11-03 10:17  初心。。。  阅读(257)  评论(0编辑  收藏  举报