更多触摸一个按钮一次 [英] Touch more one button at once

查看:146
本文介绍了更多触摸一个按钮一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我做出像机应用工作室鼓。我需要做出更多的触摸一个按钮支持一次。例如:用户触摸按钮1(!不放),它播放声音,但用户仍保持其,用户点击另一个按钮,它也播放声音。如何使编程?默认情况下onTouch或使用onclick,如果1按钮pressed,另一个按钮没有反应过来是不是释放按钮之前。

Hello i make appliction like Drum Studio. I need make support for touch more one button at once. For example: User touch button1(AND HOLD IT!) it play sound, but user still hold its, user click another button and it play sound too. How make it programmatically? By default onTouch or onClick use, if 1 button pressed, another buttons not react before button isn't released.

推荐答案

使用中,onKeyDown()事件触发每个响应和的onkeyup()事件来完成它们。

Use the onKeyDown() events to trigger each response and onKeyUp() events to finish them.

http://developer.android.com/reference/android/view/ KeyEvent.html

http://developer.android.com/reference/android/查看/ KeyEvent.Callback.html

有关沾上,您可以使用OnTouchListener

For touchs, you can use the OnTouchListener

http://developer.android.com/reference/android/查看/ View.OnTouchListener.html

和由MotionEvent确定的那种淡淡的:

and determine the kind of touch by the MotionEvent:

http://developer.android.com/reference/android/view/ MotionEvent.html

要澄清我的回应:为了使声音按住一个按钮,就可以启动时发出的声音在 ACTION_DOWN 行动 MotionEvent 触发事件,并与同一事件的 ACTION_UP 行动阻止它。

To clarify my response: To make a sound while holding one button, you can start the sound when the ACTION_DOWN action in the MotionEvent event is triggered and stop it with the ACTION_UP action of the same event.


  • 创建一个类扩展查看你持有的所有按钮的位置。

  • 重写onTouchEvent VOR该类。

  • 在不同的操作之间切换。

  • 使用event.getX()和event.getY(),以找出其中的触摸事件起源。

  • 检查哪个按钮位于该位置

  • 相应地播放声音。

这篇关于更多触摸一个按钮一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆