Android:如何防止拖动被解释为长按

发布于 2024-10-09 22:32:55 字数 227 浏览 0 评论 0原文

当我插入代码来显示上下文菜单时,它工作得很好,只是菜单不仅在固定长按后出现,而且在拖动结束时(不需要)出现。

我已经能够通过以下方法来防止这种情况:向视图添加 ScrollInProgress 标志,通过在 onCreateContextMenu(...) 方法的开头检查此标志,以及是否通过绕过将项目添加到的代码来设置该标志上下文菜单。

但是,我想知道是否有一种更简单的方法来防止拖动屏幕时创建上下文菜单。

When I inserted code to display a context menu it worked fine except that the menu appeared not only after a stationary long press but also (unwanted) at the end of a drag.

I have been able to prevent this by: adding a ScrollInProgress flag to the View, by checking this flag at the beginning of the onCreateContextMenu(...) method, and if the flag is set by by-passing the code which adds items to the context menu.

However, I wonder if there is a simpler way of preventing the creation of a context menu when the screen is dragged.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忱杏 2024-10-16 22:32:55

澄清一下,手势检测器不是在接收长按吗?
如果是,可以使用 setIsLongpressEnabled(boolean isLongpressEnabled) 禁用此功能

To clarify, it isn't the gesture detector that's picking up the long press?
If it is, this can be disabled using setIsLongpressEnabled(boolean isLongpressEnabled)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文