我想让3个按钮一次触摸,所以你可以触摸一个按钮而不用从另一个手指上移开手指。我ACTION_DOWN,ACTION_POINTER_1_DOWN和ACTION_POINTER_2_DOWN做到了到目前为止顺序:多个ACTION_DOWN事件做同样的事
public boolean onTouch(final View v, final MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
switch (v.getId()) {
case R.id.button1:
{ playSound(SOUND1, 1.0f) ;};
break;
case R.id.button2:
{ playSound(SOUND2, 1.0f) ;};
break;
case R.id.button3:
{ playSound(SOUND3, 1.0f) ;};
break;}
} else if (event.getAction() == MotionEvent.ACTION_POINTER_1_DOWN) {
switch (v.getId()) {
case R.id.button1:
{ playSound(SOUND1, 1.0f) ;};
break;
case R.id.button2:
{ playSound(SOUND2, 1.0f) ;};
break;
case R.id.button3:
{ playSound(SOUND3, 1.0f) ;};
break;}
} else if (event.getAction() == MotionEvent.ACTION_POINTER_2_DOWN) {
switch (v.getId()) {
case R.id.button1:
{ playSound(SOUND1, 1.0f) ;};
break;
case R.id.button2:
{ playSound(SOUND2, 1.0f) ;};
break;
case R.id.button3:
{ playSound(SOUND3, 1.0f) ;};
break;}
没有错误,或者如果我编译和运行我的手机在这个项目上的警告。
但是,当我第二次触摸时,会发出与第一次相同的声音。 示例:手指2按下按钮2(声音2播放)。按住按钮2上的手指2时,我用手指3触摸按钮3.我期望,声音3正在播放,但声音2再次播放。
我已经尝试过“返回true”,但没有改变任何东西。
有几个人也有这个问题,但没有人真正找到这些线程的解决方案。
亚历
更新:我刚刚发现它并不无论身在何处我点击。即使我点击一个空白区域,另一个手指所在的按钮也会再次发生反应
非常感谢,我不知道。可能你告诉我,我如何让应用程序忽略onTouch,所以OnTouchEvent被调用?这将是真棒 – user2161301 2013-04-10 17:20:04
你将不得不做一个自定义的类扩展视图并重写onTouchEvent ...在http://grepcode.com/file/repository.grepcode.com/java/ext/com.google查看源代码。 android/android/2.2_r1.1/android/widget/TextView.java#TextView.onTouchEvent%28android.view.MotionEvent%29 – sngreco 2013-04-10 20:23:58
非常感谢先生,我现在将显示宽度分为按钮所在的部分。我总是害怕X/Y的东西,因为我只是讨厌数学,但现在我对它很满意。再次感谢 – user2161301 2013-04-10 20:33:25