how to detect when MotionEvent.ACTION_MOVE is finished

痴心易碎 提交于 2019-12-07 01:32:49

问题


I need to detect in my application when user stop moving across a specific view. I'm creating something similar to marque text in my application which can interact while user is touching the view and moving across it. And I need to start scrolling the view after user lifts his finger. As I notices if I move my finger across the view a few seconds and when I lift my finger the MotionEvent.ACTION_UP is not called. The last event which I capture is ACTION_MOVE . So how can I detect when user lifts his finger after moving across the view a few seconds? Is there some kind of function which can detect that?

Here is the code which I'm using :

txt.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, final MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.e("","event down : "+event.getAction());
                handler.removeCallbacks(runnable);
                break;
            case MotionEvent.ACTION_UP:
                Log.e("","event up : "+event.getAction());
                if(myTimer!=null){
                    myTimer.cancel();
                }
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d("","move");
                // handler.removeCallbacks(runnable);
                checkX();
                break;
        }
        return true;
    }
});

Thanks in advance!


回答1:


I think the event may be sending an ACTION_CANCEL action before the gesture is finished. Or, if it drags outside of the view you're checking, it could be ACTION_OUTSIDE.

The best way to confirm/debug this would be to put a Log.d() statement in, print the MotionEvent.getActionMasked() value, and check to see what actions are being called after your ACTION_MOVE event ends.



来源:https://stackoverflow.com/questions/11257928/how-to-detect-when-motionevent-action-move-is-finished

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!