我遇到了一个问题,即 onTouchEvent 对手指停留在屏幕上并移动手指使用react。那不是我的目标。我希望 OnTouchEvent 仅在我点击屏幕时才会使用react,此后 OnTouchEvent 应重新激活自身,并且用户必须再次单击。
有人能解决我的问题吗?我的意思是我的计时器有点棘手,因为我从来没有离开过 OnTouchEvent 方法。
public boolean onTouchEvent(MotionEvent me){
if(!started){
started = true;
taptostart.setVisibility(View.GONE);
expla.setVisibility(View.GONE);
//start the timer
timer.schedule(new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
@Override
public void run() {
changePos();
}
});
}
}, 0, 20);
}else{
activateHo();
}
return false;
}
最佳答案
public boolean onTouchEvent(MotionEvent me){
if(me.getAction() == MotionEvent.ACTION_DOWN){
//Do what you want here, when the view is touched
}
return false;
}
关于java - OnTouchEvent 在触摸屏幕时 react 多次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48411297/