简体   繁体   English

Android,在 ViewGroup 的子级上捕获单点事件,但在父级上捕获双点

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

I have a zoomable ViewGroup with some childs.我有一个可缩放的 ViewGroup 和一些孩子。 User can single-tap the child to select it but can also double-tap the ViewGroup to zoom/un-zoom the canvas.用户可以单击孩子到 select 它,但也可以双击 ViewGroup 来缩放/取消缩放 canvas。

The problem is if a child handle the onTouchEvent then the parent can't detect double tap.问题是如果孩子处理onTouchEvent则父母无法检测到双击。 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."onTouchEvent方法的文档中“如果您已经消费了事件,则返回 true,如果没有,则返回 false。”

I see 2 solutions for this issue:我看到这个问题的 2 个解决方案:

  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.处理子视图上的单击,但不要在onTouchEvent方法中返回 true,因为这样也会通知父级,并且您可以处理父级的双击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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