我用一根手指触摸屏幕,LogCat显示ID:0。当我仍然用第一根手指触摸屏幕时,我用第二根手指触摸屏幕,LogCat显示ID:1。一切都很完美!
但是当我开始绕着第二根手指移动时,过了一会儿,我得到一个ACTION_POINTER_UP
事件,我不明白为什么?当我将第二根手指靠近第一根手指时,它很容易发生。但是当我用ID:0移动第一根手指时,我从未得到ACTION_POINTER_UP
。
有人能告诉我为什么会发生这种情况以及我在代码中做错了什么或者我怎么能阻止这种情况?
@Override
public boolean onTouch(View v, MotionEvent event) {
int pointerId;
int pointerIndex;
synchronized (gameLoop) {
for (int i = 0; i < event.getPointerCount() && i < 2; i++) {
id = event.getPointerCount();
// Pointer 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);
}
// Pointer up
else 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;
}