문제

I want to intercept every touch event in a given layout.

Then i want to log the event,

and propagate the event to any clickable view in the touch area.

how would i do this if i want to consume the touch event only once ?

I have read in other SOF post to use this:

(a) override onInterceptTouchEvent (MotionEvent ev) method in your top level container view or (b) you can override Activity.onUserInteraction but it also includes key and trackball actions

but then i'm not sure what happens first? event handled in the root layout or starting its children?

is the event always propagate from lower layer to upper one (parent view to its children) ?

도움이 되었습니까?

해결책

Have you tried overriding Activity.dispatchTouchEvent(MotionEvent ev)

From the docs http://developer.android.com/reference/android/app/Activity.html#dispatchTouchEvent(android.view.MotionEvent)

Called to process touch screen events. You can override this to intercept all touch screen events before they are dispatched to the window. Be sure to call this implementation for touch screen events that should be handled normally.

다른 팁

Every touch event propagates from parent view to it's children.

first, touch event came to root view.If it's onInterceptTouchEvent returns true,this event will be passed to root view's onTouchEvent.if onTouchEvent returns false,this event will be passed to root view's parent,if returns true,this touch event will disappear.if onInterceptTouchEvent returns false, this touch event will be passed to root view's children.Recursively.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top