- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个自定义 View ,我想在其上设置长按监听器。我正在使用以下代码进行设置。
final GestureDetector gestureDetector = (new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
public void onLongPress(MotionEvent e) {
Log.e("test", "Long press detected");
}
}));
public boolean onTouchEvent(MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
问题出在所有手势上,无论是单击还是双击都会调用 onLongPress。
我可以通过实现 onDown() 方法使代码正常工作,但为什么它在未实现时不起作用? onLongPress() 不应该只在手势为 onLongPress 时调用吗?
最佳答案
如果有人仍然卡在这上面,我在执行以下操作时发现发生了这种情况:
return gestureDetector.onTouchEvent(event);
与此相反:(Mcloving 在评论中发布的链接中也提到了)
gestureDetector.onTouchEvent(event);
return true;
Beware of creating a listener that returns false for the ACTION_DOWN event. If you do this, the listener will not be called for the subsequent ACTION_MOVE and ACTION_UP string of events. This is because ACTION_DOWN is the starting point for all touch events.
关于android - GestureDetector.onTouchEvent(MotionEvent e) 在所有手势上调用 onLongPress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32177573/
在聊天 (React Native) 应用程序中,我需要能够 onLongPress 在没有键盘的情况下打开上下文菜单,但在正常的点击/shortPress 上打开键盘。就像外面的大多数信使一样。 T
我有 imageView。我正在为 imageView 使用平移、捏合。有时我需要删除 imageView。所以,我使用 OnLongClickListener 来删除图像。当我使用长按我的 imag
我有一个带有 LOOONG 项目列表的微调器。我注意到,每当我尝试缓慢滚动微调器项目时,它都会突然带我回到微调器选择的顶部。我只是使用带有简单 ArrayAdapter 的标准 Spinner。这不是
有没有一种简单的方法可以使用 onLongPress 删除列表中的项目? 我想使用 OnGestureListener - onLongPress 来监听 longpress 并删除列表中的项目并通过
我想给一个按钮添加一个功能,长按会打开一个弹出窗口,用户可以从多个选项中进行选择。我想知道是否有任何组件可以渲染该 Prop ,因为据我所知,TouchableHighlight(或不透明度)的 on
我让 SimpleOnGestureListener 使用 MotionEvent 捕获 onLongPress,但问题是我无法读取事件位移,因为我总是收到 ACTION_DOWN 代码。如何实现?我
我正在尝试创建一个上下文菜单,该菜单在长按后显示,同时将手指保持在对象上,之后您将选择一个选项(通过拖动手指)并抬起它以启动操作。 我注意到一些对我来说有点奇怪的事情。首先,代码: impor
我想通过 onLongPress 从 flutter 中选择卡片。但是当我选择单张卡时,所有其他卡都被选中了吗?我想根据自己的意愿选择卡片..然后执行一些操作... 最佳答案 试试这个! import
我想在 Google Keep 中实现类似的功能。 如何在长按时启用多项选择并更改标题按钮,以便稍后删除这些选定的项目? 我当前的 Dart 代码: @override Widget build(
我知道 onLongPress会在一段时间后触发(如 500 毫秒左右)。但我想要做的是当用户按下按钮 3 秒时触发一些 Action 。其实我想设置 onLongPress 的持续时间. Eleva
我有一个 mapView,当我将手指放在 map 上时,我试图捕捉一个事件。与此类似的事件是“onTouchListener”,但我想在事件发生前按住手指几秒钟。 感谢您的帮助。 最好的,大卫。 最佳
我有布局:
根据 Android 开发者的说法: onLongPress Notified when a long press occurs with the initial on down MotionEven
有谁知道如何结合使用 onLongPress(MotionEvent e) 和 onScroll(MotionEvent e1, MotionEvent e2, float distanceX, fl
没有命名参数来配置单击以触发工具提示, 我对默认 longPress 交互的感觉是用户找不到这个深埋的功能。 我试图在 tooltip source code 中找到一些提示但失败了。 Toolti
我有一段简单的代码,它只是带有 onLongPress 属性的 TouchableOpacity ,但它似乎不起作用。 {console.log("pressed")}} activeOpacity=
我的应用程序包含一个带有 TextView 项目的 RecyclerView。在每个 TextView 项目上,我都定义了一些功能,比如将文本共享到另一个应用程序。 如何将 onLongPress 或
我需要在我的应用程序中长按 FloatingActionButton 期间执行辅助操作。 floatingActionButton: FloatingActionButton( onPressed
我在 InkWell 中有一个 TextField,带有一个 onLongPress() 回调。问题是,尽管事实上当长按 TextField 时,我在 InkWell 上看到了涟漪效应,但是 onLo
我想做两件事。首先,如果我点击“TileCell”,我想导航到 SpaceView。 NavigationLink(destination: SpaceView(space: space)) {
我是一名优秀的程序员,十分优秀!