2011-07-27 48 views
0

因此,我正在开发一个应用程序,并且需要同时按下两个按钮。 我需要在按下时触发按钮的事件(这也是同一时间)。Android多点触控帮助

想象一下一辆车 - 我已经左转,右转,前进和后退。我需要按EG。向前和向右一起右转。

这是我的方法,但由于某种原因,当我按下两个按钮时,只有第一个按下的按钮被触发......任何想法?

// Handle touches of the navigation arrows 
    public boolean onTouch(View v, MotionEvent theMotion) { 
     switch (theMotion.getAction()) { 
     // A button was PRESSED 
     case MotionEvent.ACTION_DOWN: 
      switch (v.getId()) { // Which button? 
      case R.id.freestyle_upArrow: // The upArrow 
       bt.sendNXTcommand(MOTOR_B_FORWARD, 720); 
       break; 
      case R.id.freestyle_downArrow: // The downArrow 
       bt.sendNXTcommand(MOTOR_B_BACKWARD, 720); 
       break; 
      case R.id.freestyle_leftArrow: // The leftArrow 
       bt.sendNXTcommand(MOTOR_A_LEFT, 720); 
       break; 
      case R.id.freestyle_rightArrow: // The rightArrow 
       bt.sendNXTcommand(MOTOR_A_RIGHT, 720); 
       break; 
      } 
      break; 
     // A button was RELEASED 
     case MotionEvent.ACTION_UP: 
      switch (v.getId()) { // Which button? 
      case R.id.freestyle_upArrow: // The upArrow 
       bt.sendNXTcommand(MOTOR_B_STOP, 0); 
       break; 
      case R.id.freestyle_downArrow: // The downArrow 
       bt.sendNXTcommand(MOTOR_B_STOP, 0); 
       break; 
      case R.id.freestyle_leftArrow: // The leftArrow 
       break; 
      case R.id.freestyle_rightArrow: // The rightArrow 
       break; 
      } 
      break; 
     } 
     return true; 
    } 

那么,有什么想法吗?这与我的屏幕允许的点数有关吗?

PHONE规格:三星Galaxy王牌运行Android OS固件2.2.1

问候,

丰富。

回答

1

使用

switch (event.getAction() & MotionEvent.ACTION_MASK) 

您想寻找

MotionEvent.ACTION_POINTER_UP 
MotionEvent.ACTION_POINTER_DOWN 

对于第二个手指。请记住,你会得到一个ACTION_POINTER_UP无论哪个手指首先

+0

感谢所有帮助。 – richard

1

为你检查是否取消ACTION_DOWN(单点触摸),并基于该创建逻辑ACTION_POINTER_DOWN(多点触摸)。注意:ACTION_POINTER表示多点触控本身