【问题标题】:OnTouchEvent reacts multiple while touching the screenOnTouchEvent 在触摸屏幕时做出多个反应
【发布时间】:2018-01-23 21:41:45
【问题描述】:

我遇到了问题,onTouchEvent 会对手指停留在屏幕上并移动手指做出反应。那不是我的目标。我想要,OnTouchEvent 只有在我点击屏幕时才会做出反应,之后 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;
}

【问题讨论】:

    标签: java android-studio events screen touch-event


    【解决方案1】:
    public boolean onTouchEvent(MotionEvent me){
        if(me.getAction() == MotionEvent.ACTION_DOWN){
           //Do what you want here, when the view is touched
        }
    return false;
    }
    

    【讨论】:

      猜你喜欢
      • 2014-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多