将手指滑入按钮 android
如何才能使当有人将手指滑入或滑过按钮时,该按钮就像被按下一样?
我正在寻找的一个例子是键盘应用程序。您可以在所有按键上滑动手指来播放声音。
How can I make it possible that when someone slides their finger into or over a button, the button acts as if it were getting pushed?
An example of what i'm looking for would be a keyboard app. Where you slide your fingers over all the keys to play sounds.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样使用 OnTouchListener:
通过这种方法,您将收到大量触摸事件,因为 onTouch() 会通过 MotionEvent.ACTION_MOVE 被多次调用。因此,您必须保留一个布尔值来告诉您是否是第一次调用 onTouch() 。然后,您可以在 MotionEvent.ACTION_UP 的 onTouch() 中重置该布尔值,以便下次再次使用。然而,如果您尝试执行的操作不仅仅是 2 个按钮,这可能会变得有点复杂。我认为你必须为它们中的每一个单独保留一个布尔值(或者可能是一个布尔值数组来保存它们)。并且您需要为每个按钮添加一个额外的 if(r.contains(x,y) 语句。不过,这应该让您开始走上正确的道路。
You can use an OnTouchListener like this:
With this approach though you are going to get a flood of touch events because onTouch() gets called a lot with MotionEvent.ACTION_MOVE. So you'll have to keep a boolean that tells you if its the first time you've gotten onTouch() call. Then you can reset that boolean in onTouch() for MotionEvent.ACTION_UP so it works again the next time. However this could get kind of complicated if you are trying to do more than just 2 buttons. I think you'd have to keep a boolean for each of them seperately (or perhaps an array of booleans to hold them all). and you'd need an additional if(r.contains(x,y) statements for every button. This should get you started on the right path though.