当屏幕长按时,我希望我的ACTION_MOVE跟踪用户的观看情况。
但是我的问题是我的ACTION_MOVE从未被调用过。另一方面,我的ACTION_DOWN成功运行了。
有人知道我该如何解决我的问题? 谢谢您的帮助!
这是我的代码:
onLongPressListener = new OnLongPressListener() {
@Override
public void onLongPress(MotionEvent e) {
if(isPointTouched(e) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
vibrator.vibrate(VibrationEffect.createOneShot(100, VibrationEffect.DEFAULT_AMPLITUDE));
float x;
float y;
switch(e.getAction()){
case MotionEvent.ACTION_DOWN:
x = e.getX();
y = e.getY();
Log.d("Action down", Float.toString(x));
break;
case MotionEvent.ACTION_MOVE:
x = e.getX();
y = e.getY();
Log.d("Action Move", Float.toString(x)); // i want this function to track the user movement
break;
}
}
}};
答案 0 :(得分:1)
好像OnLongPressListener
是您的自定义界面。
有View.OnLongClickListener
,但一旦执行长按便会触发。
长单击是当用户将手指长时间按住UI组件(数百毫秒)时触发的事件。它被触发一次,如果用户继续握住手指,则不会出现其他事件。
要实现您的目的,您应该实现GestureDetector
OnGestureListener
,不仅要处理事件,还要将事件划分为不同的类型(OnGestureListener
会有所帮助)
Google提供了简单的教程,说明了如何使用它: https://developer.android.com/training/gestures/detector