Java Android multi-touch:未检测到MotionEvent.ACTION\u指针\u向下
这是我代码的一部分。 我不明白为什么没有检测到Java Android multi-touch:未检测到MotionEvent.ACTION\u指针\u向下,java,android,multi-touch,motionevent,ontouch,Java,Android,Multi Touch,Motionevent,Ontouch,这是我代码的一部分。 我不明白为什么没有检测到MotionEvent.ACTION\u POINTER\u DOWN(第二个手指触摸屏幕)。 有人能解释为什么这不起作用吗 单人游戏很好用。 双人(多点触摸)不是 什么对两人有效 -当用户只按下屏幕的任意一半时,它将调用goUp() 什么对两人不起作用 -当用户按下屏幕的一半,然后按下另一半时,另一半不会调用goUp() 另外,是否有一种方法可以在模拟器上同时模拟多个触摸,以便我可以在logcat中看到logs private int pointe
MotionEvent.ACTION\u POINTER\u DOWN
(第二个手指触摸屏幕)。
有人能解释为什么这不起作用吗
单人游戏很好用。
双人(多点触摸)不是
什么对两人有效
-当用户只按下屏幕的任意一半时,它将调用goUp()
什么对两人不起作用
-当用户按下屏幕的一半,然后按下另一半时,另一半不会调用goUp()
另外,是否有一种方法可以在模拟器上同时模拟多个触摸,以便我可以在logcat
中看到log
s
private int pointerId = -1, pointerId2 = -1;
@Override
public boolean onTouch(View view, MotionEvent event) {
// Depending on the touch, depends on the direction of the ricer (up or down)
if(!TWO_PLAYER_MODE){
switch (event.getActionMasked()) {
// When finger touches the screen, ricer will accelerate up
case MotionEvent.ACTION_DOWN:
ricerView.goUp();
break;
// When finger is lifted from the screen, ricer will accelerate down
case MotionEvent.ACTION_UP:
ricerView.goDown();
}
}
else{
float touchY = event.getY();
int pointerIndex = event.getActionIndex();
int pointerID = event.getPointerId(pointerIndex);
switch (event.getActionMasked()) {
// When finger touches the screen, ricer will accelerate up
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
if( touchOnTopOfScreen(touchY) ){
pointerId = pointerID;
ricerView.goUp();
log("RV1 down Id=" + pointerID + " Y-pos=" + touchY);
}
else{
pointerId2 = pointerID;
ricerView2.goUp();
log("RV2 down Id=" + pointerID + " Y-pos=" + touchY);
}
break;
// When finger is lifted from the screen, ricer will accelerate down
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
if( pointerId == pointerID ){
ricerView.goDown();
pointerId = -1;
log("RV1 up Id=" + pointerID + " Y-pos=" + touchY);
}
if( pointerId2 == pointerID ){
ricerView2.goDown();
pointerId2 = -1;
log("RV2 up Id=" + pointerID + " Y-pos=" + touchY);
}
}
}
// Delegate the touch to the gestureDetector
mGestureDetector.onTouchEvent(event);
return true;
} // End of onTouchEvent
private boolean touchOnTopOfScreen(float y){
if(mDisplayHeight/2 > y)
return true;
else
return false;
}
问题在于你处理案件的方式
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
if( touchOnTopOfScreen(touchY) ){
pointerId = pointerID;
ricerView.goUp();
log("RV1 down Id=" + pointerID + " Y-pos=" + touchY);
}
else{//<---should be a separate if-statement
pointerId2 = pointerID;
ricerView2.goUp();
log("RV2 down Id=" + pointerID + " Y-pos=" + touchY);
}
break;
case MotionEvent.ACTION\u向下:
case MotionEvent.ACTION\u指针\u向下:
如果(触控弹出屏幕(触控)){
pointerId=pointerId;
高普();
日志(“RV1向下Id=“+pointerID+”Y-pos=“+touchY”);
}
否则{/问题在于你处理案件的方式
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
if( touchOnTopOfScreen(touchY) ){
pointerId = pointerID;
ricerView.goUp();
log("RV1 down Id=" + pointerID + " Y-pos=" + touchY);
}
else{//<---should be a separate if-statement
pointerId2 = pointerID;
ricerView2.goUp();
log("RV2 down Id=" + pointerID + " Y-pos=" + touchY);
}
break;
case MotionEvent.ACTION\u向下:
case MotionEvent.ACTION\u指针\u向下:
如果(触控弹出屏幕(触控)){
pointerId=pointerId;
高普();
日志(“RV1向下Id=“+pointerID+”Y-pos=“+touchY”);
}
否则{/问题在于你处理案件的方式
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
if( touchOnTopOfScreen(touchY) ){
pointerId = pointerID;
ricerView.goUp();
log("RV1 down Id=" + pointerID + " Y-pos=" + touchY);
}
else{//<---should be a separate if-statement
pointerId2 = pointerID;
ricerView2.goUp();
log("RV2 down Id=" + pointerID + " Y-pos=" + touchY);
}
break;
case MotionEvent.ACTION\u向下:
case MotionEvent.ACTION\u指针\u向下:
如果(触控弹出屏幕(触控)){
pointerId=pointerId;
高普();
日志(“RV1向下Id=“+pointerID+”Y-pos=“+touchY”);
}
否则{/问题在于你处理案件的方式
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
if( touchOnTopOfScreen(touchY) ){
pointerId = pointerID;
ricerView.goUp();
log("RV1 down Id=" + pointerID + " Y-pos=" + touchY);
}
else{//<---should be a separate if-statement
pointerId2 = pointerID;
ricerView2.goUp();
log("RV2 down Id=" + pointerID + " Y-pos=" + touchY);
}
break;
case MotionEvent.ACTION\u向下:
case MotionEvent.ACTION\u指针\u向下:
如果(触控弹出屏幕(触控)){
pointerId=pointerId;
高普();
日志(“RV1向下Id=“+pointerID+”Y-pos=“+touchY”);
}
否则{//在放弃几周后,我回到这个问题上,找到了我的解决方案,这实际上是一个非常简单的解决方案。现在一切都正常了!
似乎在尝试获取事件的x或y值时,需要使用event.getY(pointerIndex)
而不是event.getY()
我唯一的改变是:
int pointerIndex = event.getActionIndex();
int pointerID = event.getPointerId(pointerIndex);
float touchY = event.getY(pointerIndex);
在放弃了几个星期之后,我回到这个问题上,找到了我的解决方案,这其实是一个非常简单的解决方案。现在一切都正常了!
似乎在尝试获取事件的x或y值时,需要使用event.getY(pointerIndex)
而不是event.getY()
我唯一的改变是:
int pointerIndex = event.getActionIndex();
int pointerID = event.getPointerId(pointerIndex);
float touchY = event.getY(pointerIndex);
在放弃了几个星期之后,我回到这个问题上,找到了我的解决方案,这其实是一个非常简单的解决方案。现在一切都正常了!
似乎在尝试获取事件的x或y值时,需要使用event.getY(pointerIndex)
而不是event.getY()
我唯一的改变是:
int pointerIndex = event.getActionIndex();
int pointerID = event.getPointerId(pointerIndex);
float touchY = event.getY(pointerIndex);
在放弃了几个星期之后,我回到这个问题上,找到了我的解决方案,这其实是一个非常简单的解决方案。现在一切都正常了!
似乎在尝试获取事件的x或y值时,需要使用event.getY(pointerIndex)
而不是event.getY()
我唯一的改变是:
int pointerIndex = event.getActionIndex();
int pointerID = event.getPointerId(pointerIndex);
float touchY = event.getY(pointerIndex);
感谢您的回复,但是在将else更改为if(!touchtopofscreen)进行测试后,这不起作用。它仍然以相同的方式工作。在goUp()中,它只是更改计划线程中使用的布尔值。touchtopofscreen
返回true和false,对吗?是的,touchtopofscreen返回布尔值。好的,我目前正在尝试找到解决方案,因为据我所知,我所说的应该解决了这个问题。我以前看过这个链接,检查:感谢您的回复,但是在将else更改为if(!touchtopofscreen)进行测试后,这不起作用。它仍然以相同的方式工作。在goUp()中,它只是更改计划线程中使用的布尔值。touchtopofscreen
返回true和false,对吗?是的,touchtopofscreen返回布尔值。好的,我目前正在尝试找到解决方案,因为据我所知,我所说的应该解决了这个问题。我以前看过这个链接,检查:感谢您的回复,但是在将else更改为if(!touchtopofscreen)进行测试后,这不起作用。它仍然以相同的方式工作。在goUp()中,它只是更改计划线程中使用的布尔值。touchtopofscreen
返回true和false,对吗?是的,touchtopofscreen返回布尔值。好的,我目前正在尝试找到解决方案,因为据我所知,我所说的应该解决了这个问题。我以前看过这个链接,检查:感谢您的回复,但是在将else更改为if(!touchtopofscreen)进行测试后,这不起作用。它仍然以相同的方式工作。在goUp()中,它只是更改计划线程中使用的布尔值。touchtopofscreen
返回true和false,对吗?是的,touchtopofscreen返回布尔值。好的,我目前正在尝试找到解决方案,因为据我所知,我所说的应该解决了这个问题。我以前看过这个链接,过来看: