简体   繁体   中英

Android, catch singletap event on a child of ViewGroup but doubletap on the parent

I have a zoomable ViewGroup with some childs. User can single-tap the child to select it but can also double-tap the ViewGroup to zoom/un-zoom the canvas.

The problem is if a child handle the onTouchEvent then the parent can't detect double tap. There is a workaround to this problem?

From the documentation of the onTouchEvent method "Return true if you have consumed the event, false if you haven't."

I see 2 solutions for this issue:

  1. Handle the double tap on the child view and notify the parent view about the action double tap through a listener
  2. Handle the single tap on the child view but do not return true in the onTouchEvent method, because that way the parent will be also notified, and you can handle the double tap on the parent level.

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