imageButton_white1.setOnTouchListener(new View.OnTouchListener() { 
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
if (arg1.getAction() == MotionEvent.ACTION_DOWN) { 
                    play(R.raw.white1); 
                    imageButton_white1.setImageResource(R.drawable.white_down); 
                } 
if (arg1.getAction() == MotionEvent.ACTION_UP) { 
                    imageButton_white1.setImageResource(R.drawable.white_up); 
                } 
return false;

        });
imageButton_white2.setOnTouchListener(new View.OnTouchListener() { 
imageButton_white3.setOnTouchListener(new View.OnTouchListener() { 
...............我用这个方法只能按下一个键,滑动的时候这个键不会抬起,别的键也没有反应请问有什么办法能够实现滑键效果?

解决方案 »

  1.   

    你的返回值是false,那它怎么会执行up呢?对于onTouchEvent(),如果你返回的是false,也就表示你把这个touch事件传给了下一个 ,所以每次都只是触发down,根本不会有move或者up,除非返回true
      

  2.   

    arg1.getAction() == MotionEvent.ACTION_UP 
    只有你的手离开屏幕的时候才有Action_Up ,
    这个可能就需要你去判断MotionEvent的点(可能有很多个点)是否在ImageButton  的区域内。需要自己把所有的ImageButton遍历一遍,相当于游戏的碰撞。
     
    可能需要做的是去实现Activity的onTouchEvent,而不是给ImageButton一个OnTouchListener(个人想法)
      

  3.   


    借用你的方法我实现这个功能了,但是有个问题就是在ImageButton上滑动时不是很灵敏,在空白地方滑动非常顺畅,这是为什么呢?
      

  4.   

    OK了,我将ImageButton属性ClickAble设为false就可以了