如何检测 Android 中的触摸事件何时结束,特别是在 Webview 中。
伪代码: if (触摸事件结束) then 做一点事 结束
谢谢!
最佳答案
传递给 onTouchEvent(...)
方法的 MotionEvent
对象有一个 getAction()方法,您可以使用它来确定事件是否结束。例如:
webViews.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
//pointer down.
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_OUTSIDE:
//event has finished, pointer is up or event was canceled or the pointer is outside of the view's bounds
break;
}
return false;
}
}
此外,如果您想使用该事件(阻止其传播),只需使 onTouch(...)
方法返回 true
而不是 false
.
关于java - Android 中检测触摸事件何时结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32875635/