2014-04-28 45 views
0

我正在製作一個遊戲,如果用戶擡起手指,他們會失去,但我不知道如何檢查。如果觸摸停止,我想boolean start設置爲false。任何幫助都會非常令人滿意。接觸停止時檢測

回答

1

您可以使用OnTouchListener。您只需按照您的要求修改以下代碼

btn.setOnTouchListener(new OnTouchListener() { 

      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       // TODO Auto-generated method stub 
        int eventaction = event.getAction(); 

        switch (eventaction) { 
         case MotionEvent.ACTION_DOWN: 
          Toast.makeText(MainActivity.this, 
            "The button has been pressed " , 
            Toast.LENGTH_SHORT).show();  // finger touches the button 
          break; 

           case MotionEvent.ACTION_UP: 
          Toast.makeText(MainActivity.this, 
            "The button has been release", 
            Toast.LENGTH_SHORT).show(); 
    // finger leaves the button 
          break; 
        } 

       return false; 
      } 
     });