public boolean onInterceptTouchEvent(MotionEvent ev) {
return false;//繼續(xù)向下傳播挣菲,為true的時候就直接發(fā)送給當前viewGroup的onTouchEvent()方法處理了且不繼續(xù)向下傳播
}
Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.可以通過實現(xiàn)這個方法去攔截所有的touch事件乎完。這個可以讓viewgroup監(jiān)視分發(fā)給它的子view的事件,可以在任何時候取得當前手勢事件的控制權(quán)佑菩。
Using this function takes some care, as it has a fairly complicated interaction with {@link View#onTouchEvent(MotionEvent) View.onTouchEvent(MotionEvent)}, and using it requires implementing that method as well as this one in the correct way. Events will be received in the following order:
You will receive the down event here. 首先离唐,你會在這里接受到down事件背伴。
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.down事件可能會被這個viewGroup的一個子孩子處理掉错忱,或者給自己的onTouchEvent()事件處理了。這意味著你需要實現(xiàn)onTouchEvent()方法然后返回true,然后你就會繼續(xù)接收到剩下的手勢事件(而不是繼續(xù)向上找一個父View去處理這個事件)挂据。同時以清,onTouchEvent()方法返回true的時候,viewGroup的onInterceptTouchEvent()方法就不會再接收到陸續(xù)的方法事件崎逃,所有的touch事件會正常的直接給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.接下來的后續(xù)事件都會先傳遞到這里,然后再傳遞給處理這個事件的目標view的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 {@link MotionEvent#ACTION_CANCEL}, and all further events will be delivered to your onTouchEvent() method and no longer appear here.如果你這里返回true,你不會再接收到后續(xù)的事件:目標view會接受到相同的事件產(chǎn)生的ACTION_CANCEL勒葱。浪汪。其他的事件也會直接傳遞到你的onTouchEvent,而再也不會在onInterceptTouchEvent()方法里捕捉到。
@param ev The motion event being dispatched down the hierarchy. @return Return true to steal motion events from the children and have them dispatched to this ViewGroup through onTouchEvent(). The current target will receive an ACTION_CANCEL event, and no further messages will be delivered here. 動作事件會按層級分發(fā)凛虽。如果返回true就會從他的子孩子搶占過來這個事件且將這個事件分發(fā)給當前ViewGroup的onTouchEvent()事件處理死遭。當前的目標View會接受到ACTION_CANCEL事件,且不會再接受到后續(xù)的事件了凯旋。