监听屏幕上特定对象上发生手势的时间

发布于 2024-09-11 15:13:21 字数 160 浏览 3 评论 0原文

我的画布上会同时有多个对象,并且需要检测用户在哪个对象上执行了手势。我能想到的唯一方法是将屏幕分成多个视图并在每个视图中进行监听,但这不是很有效,所以有没有人有更好的方法,最好使用单独属于每个对象的单独手势检测器?

如果有人可以帮助我,我将非常非常非常感激,因为我一整天都在努力解决这个问题

I will have several objects on my canvas at once and need to detect over which one the user performed a gesture. The only way I can think of is splitting the screen up in to many views and listening in each but this isnt very efficient so has anyone a better way, preferably using seperate gesturedetectors that belong to each object individually?

I will be so so so grateful if someone can help me as I've been tearing my hair out trying to solve this all day

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪异←思 2024-09-18 15:13:21

如果您正在跟踪画布上对象的位置/命中框,您可以将其与 MotionEvent 中的 RawX 和 RawY 值进行比较。

If you are tracking the position/hitbox of your objects on the canvas you can compare that to the RawX and RawY values in the MotionEvent.

冷默言语 2024-09-18 15:13:21
  @Override
        public boolean onDoubleTap(MotionEvent e) {
            float e_x = e.getRawX();
            float e_y = e.getRawY();
            if(e_x > 100 && e_x < 200 && e_y > 400 && e_y < 600){
            // do something
            }
            return true ;
        }

这就是我所做的,只需检查坐标

  @Override
        public boolean onDoubleTap(MotionEvent e) {
            float e_x = e.getRawX();
            float e_y = e.getRawY();
            if(e_x > 100 && e_x < 200 && e_y > 400 && e_y < 600){
            // do something
            }
            return true ;
        }

This is what i did, just check for coordinates

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文