如何检测MotionEvent.ACTION_MOVE何时完成 [英] how to detect when MotionEvent.ACTION_MOVE is finished
问题描述
当用户停止在特定视图中移动时,我需要在我的应用程序中进行检测。我在我的应用程序中创建类似于marque文本的东西,当用户触摸视图并在其中移动时,可以进行交互。我需要在用户抬起手指后开始滚动视图。正如我注意到,如果我将手指移过视图几秒钟,当我抬起手指时,不会调用 MotionEvent.ACTION_UP
。我捕获的最后一个事件是 ACTION_MOVE
。那么我怎样才能检测用户在几秒钟内移动视线后何时抬起手指?是否有某种功能可以检测到它?
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;
}
});
提前致谢!
推荐答案
我认为该事件可能是在手势完成之前发送 ACTION_CANCEL
动作。或者,如果它在您正在检查的视图之外拖动,则可能是 ACTION_OUTSIDE
。
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
.
最佳方式确认/调试这将是一个 Log.d()
语句,打印 MotionEvent.getActionMasked()
值,并检查 ACTION_MOVE
事件结束后正在调用的操作。
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.
这篇关于如何检测MotionEvent.ACTION_MOVE何时完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!