Given that there is a ViewGroup with several children. Regarding this ViewGroup, I would like it to manage all of the MotionEvent for all of its children, which says that VG will 1. be able to intercept all events before they are sent to the target (children)
2. First, the VG consumes the event and determines whether the event will be further sent to the target child.
3. DOWN, MOVE, UP, I would like them to be relatively independent, which means that VG can eat DOWN, but give MOVE and UP to the children.
I read the UI Handling SDK guide, I knew event listeners, handlers, ViewGroup.onInterceptTouchEvent (MotionEvent) and View.onTouchEvent (MotionEvent).
Here is my example,
@Override public boolean onInterceptTouchEvent (MotionEvent event) { if (MotionEvent.ACTION_DOWN == event.getAction()) { return true; } return super.onInterceptTouchEvent(event); } @Override public boolean onTouchEvent(MotionEvent event) { if (MotionEvent.ACTION_DOWN == event.getAction()) { return true; } else { if (!consumeEvent(event)) {
To be able to have some events, I must return true in both methods when the DOWN event occurred, because the SDK said so. Then I could see MOVE in onTouchEvent. However, in my case, I have no idea how to send events to children.
Above dispatchTouchEvent led to an infinite loop, which was understandable since VG itself could be the target. I can’t say which one will be targeted at that moment, MotionEvent didn’t give a hint, so dispatchTouchEvent was absolutely useless. Does anyone help me? Thanks.
source share