onInterceptTouchEvent / onTouchEvent響應事件的詳析

onInterceptTouchEvent(),onTouchEvent() 默認返回falsespa

注:事件分發機制是由 dispatchTouchEvent() 開始分發的事件

onInterceptTouchEvent()io

ACTION_DOWN ------------ return true: ---→  將事件傳遞給該view下的 onTouchEvent()                                                                                                                                                                                                                                                                                                                          ACTION_MOVE ACTION_UP 都將直接由 onTouchEvent() 響應                                                                      方法

                                                                        該view的 onInterceptTouchEvent() 將沒法響應 ACTION_MOVE,ACTION_UPdi

                            ------------ return false:    ↓   將事件向下傳遞(判斷是否存在下級)view

                                                              無下級: 將事件傳遞給該view下的 onTouchEvent()(等同於返回true)vi

                                                              有下級: 判斷下一級是View 仍是 ViewGroupco

                                                                           ViewGroup : 將事件傳遞給下一級的 onInterceptTouchEvent(),一直向下傳遞上傳

                                                                           View: 將事件傳遞給下一級的 onTouchEvent() return

                                                               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()

相關文章
相關標籤/搜索