java - Android 中检测触摸事件何时结束

标签 java android android-studio

如何检测 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/

相关文章:

java - Youtube Data-api代码停止工作-更新视频元数据功能

java - 如何获取日期之间的月份数?

android - CSS背景完全适合Android

Android 应用程序设计分辨率

android - 无法在 Android 中显示 map

java - 如何在 Liferay 日历中获取单个 google 重复事件的 SyncEntryId?

java - 读取可以是整数或字符的输入的简单方法是什么?

android - 资源 'attr/tint' 与配置的重复值

java - LinearLayoutManager 不能在 Fragment 中使用

Android Studio v1.3 检查未经检查的权限使用情况