情況1:return true
則事件只會在當前方法內消耗掉,且不會向下傳遞,最後傳給Activity.
|
|
情況2:return false
則事件只會在當前方法內消耗且不會向下傳遞,最後傳給Activity。
但是不同於情況1,呈U型傳遞的過程不會傳到當前的佈局
|
|
情況3:super.dispatchTouchEvent(MotionEvent)
整個過程會經歷當前ViewGroup的三個觸摸事件,dispatchTouch -> interceptTouch -> onTouchEvent。
|
- You will receive the down event here.
按下的事件會在這裏接收。 - 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.
按下事件將會被這視圖裏面的子視圖處理,否則就被分發onTouchEvent 方法去處理 ; 這就意味着你應該實現 onTouchEvent 返回true, 所以你將會繼續看到剩下的手勢。而且,通過從onTouchEvent方法返回true,你不會在onInterceptTouchEvent方法中接收任何事件並且所有的觸摸處理一定會在onTouchEvent中正常發生。 - 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,每個緊跟着的事件將會 傳遞到這裏然後分發到目標的的OnTouchEvent(). - 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 MotionEvent.ACTION_CANCEL, and all further events will be delivered to your onTouchEvent()
method and no longer appear here.
如果你返回true,你就不會接收到以下事件:目標視圖將接收到同樣的事件而且只有MotionEvent.Action_Cancel,而且所有未來的事件將會傳遞到你的onTouchEvent 方法,並且不在會出現在這裏。
情況1:return true 事件傳遞將按照dispatch-> intercept-> onTouch進行傳遞,最終返回到Activity。 |
|
情況2:return false
正常傳遞
|
|
情況3: super.onInterceptTouchEvent(ev);
正常傳遞
|