简体   繁体   中英

Handling onTouchEvent and onTouch between parent ViewGroup with zoom, and child ImageView?

I have a custom ZoomableViewGroup that overrides onTouchEvent to handle pan/fling movements, and uses ScaleGestureDetector.SimpleOnScaleGestureListener to handle zoom gestures. This ZoomableViewGroup works fine until I try to use onTouch in children of the ViewGroup.

Inside this ZoomableViewGroup I have multiple ImageViews that serve as buttons. I would like the functionality of the parent to take precedent over the onTouch of the children. As it stands it seems the child ImageViews are intercepting touchevents and not passing them to it's parent.

I would like to know what a good method of ensuring that a parent's touch functionality is preserved over it's children's touch functionality.

Any help or suggestions would be greatly appreciated!

EDIT:

Your response has been extremely helpful Jason, I think i'm starting to make sense of this situation better now. I've been messing around with my zoomable view groups onInterceptTouchEvent method, but am still a bit confused

  • you touch the screen over an ImageView inside of my zoomable ViewGroup,
  • ViewGroup.onInterceptYouchEvent gets ACTION_DOWN
  • i want my ViewGroup to act IF the event is a pan or zoom gesture, so I will return 'true'for ACTION_DOWN
  • it appears that when my viewgroup consumes ACTION_DOWN event, it sends my ImageView.onTouch 'ACTION_CANCEL'
  • I want my ImageView.onTouch method to respond to an ACTION_UP event if the ACTION_MOVE preceding it is less than a slop value.

how is my ImageView supposed to get the relevant ACTION_UP info if it's aleady recieved an ACTION_CANCEL from it's parent ViewGroup?

please correct me if I'm interpreting what's happening wrong here too! Thanks Again!

The basic idea is to override onInterceptTouch in the parent view and provide logic there for whether or not to pass on the touch to the child view (return false ) or to actually allow the parent view to intercept/consume the touch (return true ). Your logic can be spatial (perhaps the edges of the parent view are special, but not the interior), or gestural (perhaps horizontal swipes trigger something at the parent view level and vertical swipes trigger something at the child view level, or, in your case, simple taps get passed to the child buttons, but two finger gestures get consumed by the parent).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM