Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Views OnTouch Events

Tags:

android

We are developing an application where we need to capture MotionEvents from multiple views simultaneously. When we try to do so, Android only dispatches events to the first touched view and, when touching another view simultaneously, it gives us an ACTION_POINTER_DOWN on the first view only, even if the pointer coordinates are outside its bounds and inside the other views'.

Is there any way we can get events dispatched to every touched view (in separate calls to OnTouch)?

We believe intercepting the touch events from a parent view and then manually dispatching them to each view might work, but even if it does, it would not be practical for what we are trying to achieve. Is there an easier way?

like image 421
Christian Avatar asked Feb 10 '11 14:02

Christian


2 Answers

At least Android 3.0 adds support for splitting touch events between multiple Views.

Split touch events is enabled by default when AndroidManifest <uses-sdk> defines either android:minSdkVersion="11" or android:targetSdkVersion="11". For explanation See android:splitMotionEvents and android:windowEnableSplitTouch

like image 184
vivid_voidgroup Avatar answered Nov 06 '22 14:11

vivid_voidgroup


Touch event is first catched by the view currently in focus. If you touched 1 view and have "consumed" event and are working with it, any other events will be dispatched to this view, no matter where you click.

If you return false from your touchListener (thus saying that event is not consumed) it will be delegated down to other views, but on another separate click new event will be dispatched to other view.

http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part-3-understanding-touch-events/1775

http://developer.android.com/guide/topics/ui/ui-events.html

like image 37
Alex Orlov Avatar answered Nov 06 '22 14:11

Alex Orlov