0

如何检测多点触控事件?我尝试的代码是:

ImageView im = (ImageView) findViewById(R.id.imageView1);
im.setOnTouchListener(new OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_POINTER_DOWN:
        Log.e("case MotionEvent.ACTION_POINTER_DOWN","case MotionEvent.ACTION_POINTER_DOWN");
        break;
      case MotionEvent.ACTION_DOWN:
        Log.e("case MotionEvent.ACTION_DOWN","case MotionEvent.ACTION_DOWN");
        break;
      case MotionEvent.ACTION_UP:
        Log.e("case MotionEvent.ACTION_UP","case MotionEvent.ACTION_UP");
        break;
      case MotionEvent.ACTION_MOVE:
        Log.e("case MotionEvent.ACTION_MOVE","case MotionEvent.ACTION_MOVE");
        break;
    }
    return false;
  }
});

它检测到第一次触摸,日志 cat 中的输出是 MotionEvent.ACTION_POINTER_DOWN。如何知道是否发生了第二次触摸?

4

2 回答 2

2

您应该在 xml 布局文件中将以下行添加到 imageView1:

android:longClickable="true"

这将启用长点击和其他事件也将被接收。

于 2012-11-13T12:58:16.427 回答
2

有很多方法可以做到这一点,所以你可以在这里选择其中一些链接已经编写了一个完整的应用程序来处理多点触控。

多点触摸

多点触控

于 2012-11-13T13:04:36.663 回答