Android 3手指触摸检测

发布于 2024-11-04 20:56:28 字数 780 浏览 1 评论 0原文

我使用以下代码成功地记录了在屏幕上触摸的两个手指的坐标:

case MotionEvent.ACTION_MOVE:
Log.d("TOUCH", "test ACTION MOVE" + event.getPointerCount());
Log.d("TOUCH", "test ACTION MOVE ID" + event.getPointerId(0) + " "+event.getPointerId(1));
if(event.getPointerCount()==3)
{

x0 = (int) event.getX(event.getPointerId(0));
y0 = (int) event.getY(event.getPointerId(0));
x1 = (int) event.getX(event.getPointerId(1));
y1 = (int) event.getY(event.getPointerId(1));
x2 = (int) event.getX(event.getPointerId(2));
y2 = (int) event.getY(event.getPointerId(2));

Log.d("TOUCH", "test ACTION DOWN " + " values = " + x0 + " " + y0 + " "
+ x1 + " " + y1+ " "+x2 + " " + y2);
}

但是在上面的代码中,我无法在单个实例中检测到两个以上的触摸点。即使pointerCount()也永远不会超过2。

我怎样才能获得超过2个手指的触摸坐标?我在 Android 2.2 上运行此代码

I am successfully able to record the coordinates of the two fingers being touched on the screen using the following code:

case MotionEvent.ACTION_MOVE:
Log.d("TOUCH", "test ACTION MOVE" + event.getPointerCount());
Log.d("TOUCH", "test ACTION MOVE ID" + event.getPointerId(0) + " "+event.getPointerId(1));
if(event.getPointerCount()==3)
{

x0 = (int) event.getX(event.getPointerId(0));
y0 = (int) event.getY(event.getPointerId(0));
x1 = (int) event.getX(event.getPointerId(1));
y1 = (int) event.getY(event.getPointerId(1));
x2 = (int) event.getX(event.getPointerId(2));
y2 = (int) event.getY(event.getPointerId(2));

Log.d("TOUCH", "test ACTION DOWN " + " values = " + x0 + " " + y0 + " "
+ x1 + " " + y1+ " "+x2 + " " + y2);
}

But In the above code im not able to detect more then 2 touch points at a single instance. Even the pointerCount() never goes above 2.

How can I get the touch coordinates for more then 2 fingers? Im running this code on Android 2.2

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

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

发布评论

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

评论(4

小姐丶请自重 2024-11-11 20:56:28

前段时间有人问过这个问题,但无论如何。答案是,虽然 Android 可以跟踪 256 个手指,但当前的实现将其限制为 2 个手指。

我不确定蜂窝,但我猜它有同样的“问题”。

This was asked some time ago, but anyway. The answer is that although android could track 256 fingers, the current implementation limits this to 2 fingers.

I'm not sure about honeycomb, but I guess that it has the same "issue".

旧情勿念 2024-11-11 20:56:28

我已经在一些 Android 2.3.5 设备以及我迄今为止测试过的所有 3.x 和 4.x 设备上确认了 4 次触摸。看来至少从 API 8+ 开始,支持两次以上触摸,但它依赖于设备。

I've confirmed 4 touches on some Android 2.3.5 devices, and every 3.x and 4.x device I've tested so far. It seems that at least from API 8+, more than two touches is supported, but it's device-dependent.

不回头走下去 2024-11-11 20:56:28

使用两个以上手指的多点触控只能在 android 4.1.2 版本或更高版本中执行,并且不同的公司根据自己的需求和应用程序定制了 android 版本,即在 4.1.2 版本中,Qmobile 仅支持五个手指,但伟大的三星公司使用超过11根手指

multitouch which uses more than two fingers can only be performed in android 4.1.2 version or above and also different companies have customized the android versions according to their needs and apps i.e in 4.1.2 version the Qmobile just support five fingures but the great samsung company uses more than 11 fingers

凹づ凸ル 2024-11-11 20:56:28
     firstFingerX = MotionEventCompat.getX(ev, 0); firstFingerY = MotionEventCompat.getY(ev, 0);
 if (numberOfFingers == 2) {
     Log.e("mine", "Integer: " + String.valueOf((int)MotionEventCompat.getY(ev, 1)));
     secondFingerX = MotionEventCompat.getX(ev, 1); secondFingerY = MotionEventCompat.getY(ev, 1);
 }
 if (numberOfFingers == 3) {
     Log.e("mine", "Integer: " + String.valueOf((int)MotionEventCompat.getY(ev, 2)));
     thirdFingerX = MotionEventCompat.getX(ev, 2); thirdFingerY = MotionEventCompat.getY(ev, 2);

 }
     firstFingerX = MotionEventCompat.getX(ev, 0); firstFingerY = MotionEventCompat.getY(ev, 0);
 if (numberOfFingers == 2) {
     Log.e("mine", "Integer: " + String.valueOf((int)MotionEventCompat.getY(ev, 1)));
     secondFingerX = MotionEventCompat.getX(ev, 1); secondFingerY = MotionEventCompat.getY(ev, 1);
 }
 if (numberOfFingers == 3) {
     Log.e("mine", "Integer: " + String.valueOf((int)MotionEventCompat.getY(ev, 2)));
     thirdFingerX = MotionEventCompat.getX(ev, 2); thirdFingerY = MotionEventCompat.getY(ev, 2);

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