我发现当我停止在屏幕上移动手指时,不会触发Android onTouch事件,因此我无法正确获取游戏中每一个刻度的指针计数。
@Override
public boolean onTouch(View v, MotionEvent e) {
pointerCount = e.getPointerCount();
}
有人对此有解决方案吗?
最佳答案
试试看:
sound1.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) {
pressed1 = true;
mp1 = MediaPlayer.create(MainClass.this, R.raw.item1);
mp1.start();
sound1.setBackgroundResource(R.drawable.pad_pressed);
if (looping == true) {
mp1.setLooping(true);
} else if (looping == false) {
mp1.setLooping(false);
}
return true;
} else if (event.getAction() == android.view.MotionEvent.ACTION_UP) {
pressed1 = false;
mp1.stop();
mp1.reset();
mp1.release();
sound1.setBackgroundResource(R.drawable.pad_normal);
return true;
}
return false;
}});