Android 多点触控

发布于 2024-12-14 12:35:32 字数 388 浏览 3 评论 0原文

因此,我尝试使用 onTouchEvent 检查多个屏幕触摸,但它似乎仍然只读取第一次触摸。有人可以帮忙吗? 这是我的代码:

public boolean onTouchEvent(MotionEvent e)
{
    int num = e.getPointerCount();
    for(int a = 0;a<num;a++)
    {
    int x = (int) e.getX(e.getPointerId(a));
    int y = (int) e.getY(e.getPointerId(a));
    check(x,y);
    }

    return false;
}

我浏览了很多此类论坛,但大多数与多点触控相关的主题都是关于缩放的。

So, I am trying to check multiple screen touches with an onTouchEvent, but it still only seems to read the first touch. Can anyone help?
Here is my code:

public boolean onTouchEvent(MotionEvent e)
{
    int num = e.getPointerCount();
    for(int a = 0;a<num;a++)
    {
    int x = (int) e.getX(e.getPointerId(a));
    int y = (int) e.getY(e.getPointerId(a));
    check(x,y);
    }

    return false;
}

I looked over a lot of these forums, but most of the multi touch related topics were about zooming.

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

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

发布评论

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

评论(2

青萝楚歌 2024-12-21 12:35:32

您的代码在我的设备(Nexus S、Android 2.3)上运行良好。它读取所有触摸。

这是测试代码:

  public boolean onTouchEvent(MotionEvent e) {
    int num = e.getPointerCount();
    for (int a = 0; a < num; a++) {
      int x = (int) e.getX(e.getPointerId(a));
      int y = (int) e.getY(e.getPointerId(a));
      Log.d(TAG, "pointer_" + e.getPointerId(a) + ": x = " + x
          + ", y = " + y);
    }
    return false;
  }

这是日志(用 5 个手指触摸):

11-09 17:32:55.542: D/Touch(20594): pointer_0: x = 169, y = 613
11-09 17:32:55.542: D/Touch(20594): pointer_1: x = 407, y = 289
11-09 17:32:55.542: D/Touch(20594): pointer_2: x = 62, y = 441
11-09 17:32:55.542: D/Touch(20594): pointer_3: x = 251, y = 202
11-09 17:32:55.542: D/Touch(20594): pointer_4: x = 132, y = 256

您的 Android 设备和操作系统版本是什么?

Your code works well on my device (Nexus S, Android 2.3). It reads all touches.

Here is the test code:

  public boolean onTouchEvent(MotionEvent e) {
    int num = e.getPointerCount();
    for (int a = 0; a < num; a++) {
      int x = (int) e.getX(e.getPointerId(a));
      int y = (int) e.getY(e.getPointerId(a));
      Log.d(TAG, "pointer_" + e.getPointerId(a) + ": x = " + x
          + ", y = " + y);
    }
    return false;
  }

Here is the log (touch with 5 fingers):

11-09 17:32:55.542: D/Touch(20594): pointer_0: x = 169, y = 613
11-09 17:32:55.542: D/Touch(20594): pointer_1: x = 407, y = 289
11-09 17:32:55.542: D/Touch(20594): pointer_2: x = 62, y = 441
11-09 17:32:55.542: D/Touch(20594): pointer_3: x = 251, y = 202
11-09 17:32:55.542: D/Touch(20594): pointer_4: x = 132, y = 256

What is your Android device and OS version?

若能看破又如何 2024-12-21 12:35:32

发生这种情况是因为当您想要移动时,您的方法将返回 false。所有多指操作都应返回 true

This happens because your method will return false when you want to make move. All multi finger actions should return true.

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