How can i maintain ontouch events handled by a widget even if touch coords are not inside the widget anymore, in android

StackOverflow https://stackoverflow.com/questions/6803959

Question

Sorry for the complex question let me explain. I've created a custom widget that handles some ontouch events. What i want to do is when i start a touch event on that custom widget (onDown) i want that widget to keep handling these event even if the absolute coordinations are not in that widget.

I have a scrollview and on top of that(inside the scrollview) a widget that handles (left - right) scrolls. But if i move the finger vertically the ontouch events are consumed and handled by the scollview. If there a way to forbit scrollview to handle touch events , or better force the custom widget to keep handling the touchEvent, if i start the ontouchEvent inside the custom widget?

UPDATE I came across that http://groups.google.com/group/android-framework/browse_thread/thread/2cdd4269dfb2772e?pli=1 .

That works in my case if the custom widget is NOT inside a scrolling view like "ScrollView". Trying to solve the "Beeing inside a scrolling object. How to not send these on touchevents to the parent? Returning true doesn't solve the problem

Was it helpful?

Solution

In your widget's onTouch handler (e.g. during ACTION_MOVE), call the parent.requestDisallowInterceptTouchEvent(true). That method basically is asking the parent (in your case the scrollview) and its ancestor not to intercept the touch event.

OTHER TIPS

You will need to implement a special subclass of ScrollView, which allows your widget to tell it to disable scrolling when desired (so it won't start scrolling after enough movement and take events from your widget). The custom ScrollView can override this method:

http://developer.android.com/reference/android/widget/ScrollView.html#onInterceptTouchEvent(android.view.MotionEvent)

When you don't want the base class to consume touch events for scrolls, return false here instead of calling the base implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top