0
在下面的代碼中,我正在測試我的設備上的多點觸摸。我遇到的問題是移動操作。如果我用一根手指觸摸屏幕,我會在Logcat中獲得觸摸輸入的ID,並且當我用另一個手指觸摸屏幕並開始移動屏幕時,我得到兩個手指的ID,儘管手指沒有「不要動!我很困惑,需要一些幫助來改進我的代碼。ID多點觸摸問題
@Override
public boolean onTouch(View v, MotionEvent event) {
int pointerId;
int pointerIndex;
synchronized (gameLoop) {
for (int i = 0; i < event.getPointerCount() && i < 2; i++) {
num = event.getPointerCount();
//id = event.getPointerId(i);
// Down
if(event.getActionIndex() == i && (event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN || event.getActionMasked() == MotionEvent.ACTION_DOWN)) {
int j = event.getPointerCount();
int id = event.getPointerId(i);
String numDown = Integer.toString(j);
String sId = Integer.toString(id);
Log.i("Test", "Number DOWN: " + numDown + " ID: " + sId);
}
// Move
if(event.getActionMasked() == MotionEvent.ACTION_MOVE) {
int j = event.getPointerCount();
int id = event.getPointerId(i);
String numDown = Integer.toString(j);
String sId = Integer.toString(id);
Log.i("Test", "Moving: " + numDown + " ID: " + sId);
}
// Up
if(event.getActionIndex() == i && (event.getActionMasked() == MotionEvent.ACTION_POINTER_UP || event.getActionMasked() == MotionEvent.ACTION_UP)) {
int k = event.getPointerCount();
int kid = event.getPointerId(i);
String numUp = Integer.toString(k);
String ssId = Integer.toString(kid);
Log.i("Test", "Number UP: " + numUp + " ID: " + ssId);
}
}
}
return true;
}