gpt4 book ai didi

Android 多点触控 : Pointers with index > 0 not triggering event. Action_Move

转载 作者:搜寻专家 更新时间:2023-11-01 07:55:24 26 4
gpt4 key购买 nike

在我的多点触控程序中,我遇到了一个运行时错误,其中指针在屏幕上滑动的多点触控逻辑 (MotionEvent.ACTION_MOVE) 仅由初始指针输入。这意味着我的 switch 语句中用于 case ACTION_MOVE 的代码只能由触摸屏幕的第一根手指访问,也就是指针索引 = 0。以下是我的代码的相关部分:

public boolean onTouchEvent(MotionEvent event) {
// get pointer index from the event object
int pointerIndex = event.getActionIndex();
// get pointer ID
int pointerId = event.getPointerId(pointerIndex);
// get masked (not specific to a pointer) action
int maskedAction = event.getActionMasked();

switch (maskedAction) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN: {
// We have a new pointer. Lets add it to the list of pointers
PointF f = new PointF();
f.x = event.getX(pointerIndex);
f.y = event.getY(pointerIndex);
mActivePointers.put(pointerId, f);
Log.d("Multitouch", "x coord = " + Float.toString(f.x));
Log.d("Multitouch", "y coord = " + Float.toString(f.y));
break;
}
case MotionEvent.ACTION_MOVE: { // a pointer was moved
Log.e("Multitouch", "Pointer"+ Integer.toString(pointerId) +" is moving");
for (int size = event.getPointerCount(), i = 0; i < size; i++) {
PointF f = mActivePointers.get(event.getPointerId(i));
if (f != null) {
f.x = event.getX(i);
f.y = event.getY(i);
}
}
break;
}
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL: {
mActivePointers.remove(pointerId);
break;
}
}
invalidate();
return true;
}

不用说,我希望 Action_Move 中的代码由任何指针触发,而不仅仅是初始指针。是什么阻止索引零以外的指针触发移动事件?

最佳答案

如文档中所述,MotionEvent.getActionIndex() 仅返回 ACTION_POINTER_UPACTION_POINTER_DOWN 的索引 (http://developer.android.com/reference/android/view/MotionEvent.html#getActionIndex%28%29)。但是,您在日志输出中使用由所述函数返回的指针索引生成的指针 ID。因此,日志不正确,因为该函数未返回您期望的结果。

关于Android 多点触控 : Pointers with index > 0 not triggering event. Action_Move,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28417492/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com