android - 您如何检查是否有人触摸屏幕并向特定方向拖动?

标签 android screen

我想检查是否有人将手指放在屏幕中央并向右拖动,如何实现?

解决方案: 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/

相关文章:

android - 在Android中使用asmack在接收文件时获取ExecutionException

android - 节点尚未附加到 `PropsAnimatedNode.updateView` 中的 View

javascript - 如何使用javascript检测移动设备屏幕是否关闭

android - 从服务检测屏幕方向变化

Android powermanager/唤醒锁问题

c++ - 在 windows 下获取实际屏幕 dpi/ppi

android - 通知中的缩放、裁剪图标

android - 当我尝试在 Mac OS X 上运行 Android 模拟器时,我得到 'Command Not Found'

android - onSensorChanged(...) 中是否需要同步?

c# - 当笔记本电脑上正在运行另一个程序时,如何将 C# WPF 输出分配到电视屏幕