我想检查是否有人将手指放在屏幕中央并向右拖动,如何实现?
解决方案: http://www.codeshogun.com/blog/2009/04/16/how-to-implement-swipe-action-in-android/
最佳答案
您可以实现 onTouchListener 并执行如下操作:
public boolean onTouch(View view, MotionEvent event) {
int currentX = event.getX();
if(event.getAction() == MotionEvent.ACTION_MOVE) {
// oldX would be defined as a private property of the class (most likely an Activity)
if(currentX > oldX) {
// moving right
oldX = currentX;
} else {
// moving left or not moving at all
oldX = currentX;
}
}
return true;
}
您或许可以尝试一下,让它按照您想要的方式工作。
关于android - 您如何检查是否有人触摸屏幕并向特定方向拖动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3686576/