Saturday, March 31, 2012

Re: [android-developers] Prevent a click from being consumed, to pass to containers onTouchEvent

Take a look at ScrollView or AbsListView:

https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/ScrollView.java#L438

The basic idea is to override onInterceptTouchEvent, consume the initial ACTION_DOWN and then figure out if the user is trying to scroll/fling/zoom or not.

In the latter case, onInterceptTouchEvent should eventually (for some subsequent event) return false, thus enabling the user to interact with child views.

-- K

On 04/01/2012 01:04 AM, momo wrote:
I've got a container that allows 2-d scrolling, fling, pinch etc.  This has several layers within it - a viewgroup for image tiles, another for path drawing, another for markers, etc.

This all works fine.  However, in one particular implementation I have several "invisible buttons" to indicate hotspots (which are basically ImageViews with transparent backgrounds).  When tapped, an action occurs.

The problem is that with these hotspots (which cover a good deal of the entire area), the touch event is consumed and not passed to the container's TouchEvent, so the container does not scroll.

My first attempt was to create a custom view for the hotspots, and override onTouchEvent, returning false on ACTION_DOWN and true on ACTION_UP (so the event fires when the finger goes up, which is fine).  However, it seems that when returning false on ACTION_DOWN prevents ACTION_UP from ever firing.

I also tried overriding onInterceptTouchEvent on the scrolling container, and "stealing" the ACTION_DOWN event from child views - this had the same result.

How can I continue to drag the container (whether or not the down event happened on a hotspot/child view), and react on ACTION_UP when a hotspot is clicked?

TYIA.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate