在屏幕上滑动手指激活按钮,就像按下按钮一样

发布于 2024-10-31 08:54:51 字数 508 浏览 0 评论 0原文

如果我的标题不够清楚,我将详细解释它:

假设我们有一个充满多个按钮(10 多个)的屏幕,我们按下一个按钮,激活 onTouch/onClick。如果我们现在移动手指而不抬起它,我希望它激活它滑过的任何其他按钮。在这种特殊情况下,我希望当您滑过虚拟钢琴时播放声音。

我知道 onTouchListener 解决方案,您可以在其中注册每个 ACTION_MOVE 并找到一些激活新事件的边界,但如果您有多个按钮并希望允许平滑滑动而不延迟,那么这远非最佳。

我还阅读了此帖子,其中建议我们将视图的 touchListener 与活动中的手势侦听器结合起来,但再一次,这对于我的情况来说根本不是最佳选择。

我还没有尝试将触摸监听器与手势监听器结合起来,但如果有人告诉我他们没有其他方法可以做到这一点,我会继续这样做。

In case my title wasn't clear enough, I'll explain it in detail:

Say we have a screen filled with multiple buttons (10+), and we press down on one, activating onTouch/onClick. If we now move the finger, without lifting it, I want it to activate any other button it slides over. In this particular case, I want sound to be played when you slide over a virtual piano.

I know about the onTouchListener-solution where you register every ACTION_MOVE and find some boundaries that activates new events, but that's far from optimal if you have multiple buttons and want to allow smooth sliding without delay.

I also read this thread which suggested that we combine the touchListener of the View with a gesturelistener from the activity, but once again, this does not feel at all optimal for my situation.

I have not tried combining touchlistener with gesturelistener yet, but I will go ahead and do so if someone tells me they have no other way of doing this.

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

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

发布评论

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

评论(2

闻呓 2024-11-07 08:54:51

在我看来,正确的方法是忘记按钮,并创建一个绘制整个键盘的自定义视图。在此视图中,您可以按照您喜欢的方式处理触摸事件。您甚至不需要手势检测器,只需分析运动事件的动作和坐标,非常简单。

我不明白你所说的 ACTION_MOVE 和延迟是什么意思。为了最大限度地减少延迟,请对 ACTION_DOWN 做出反应,如果在按下状态时悬停其他键,则对 ACTION_MOVE 做出反应。不可能比这更快了。对于按钮来说,存在一个重要的延迟,因为当用户在 ACTION_UP 上抬起手指时会触发 onClick() 事件。

按钮并不像您所描述的那样工作。这个想法是,如果用户点击一个按钮,然后同时将手指移开,则不会触发周围其他视图上的 onClick 事件。这可以防止虚假点击。

In my opinion, the proper way of doing this is to forget about buttons, and create a custom view which draws the entire keyboard. In this view you can handle touch events the way you like. You do not even need the gesture detector, just analyze the action and coordinates of motion events, it's very easy.

I don't understand what you mean about ACTION_MOVE and delays. To minimize delay, react on ACTION_DOWN, and then on ACTION_MOVE if it hovers other keys while in down state. It can't be any faster than that. With buttons there is an important delay because the onClick() event is triggered when the user lift the finger, on ACTION_UP.

Buttons are just not meant to work as you describe. The idea is that if a user taps on a button and then move his finger away at the same time it does not trigger onClick events on other views around. This prevents bogus clicks.

失去的东西太少 2024-11-07 08:54:51

实际上,我采取了“简单”的方法,使用带有 onTouch 方法的按钮,使用 ACTION_DOWNACTION_MOVE 以及与 event.getX()< 相结合的坐标计算/code> 和 event.getY() 允许我检测当前悬停的按钮。它有 13 个按钮,无延迟。

I actually took the "easy" way out and used buttons with an onTouch-method using ACTION_DOWN and ACTION_MOVE with coordinate calculations that combined with event.getX() and event.getY() allows me to detect which button is currently hovered. It's lag free with 13 buttons.

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