这是我的代码。
当返回false时,只能调用ACTION_DOWN,当返回true时,所有操作都可以,为什么?
aView = findViewById(R.id.a1);
aView.setOnTouchListener(new OnTouchListener(){
//@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
System.out.println("Gallery onTouch");
if(event.getAction()==MotionEvent.ACTION_MOVE){
Log.e("touchtest", "ACTION_MOVE");
System.out.println("ACTION_MOVE ");
}else if(event.getAction()==MotionEvent.ACTION_UP){
Log.e("touchtest", "ACTION_UP");
System.out.println("ACTION_UP ");
}else if (event.getAction()==MotionEvent.ACTION_DOWN){
Log.e("touchtest", "ACTION_DOWN");
}
return true;
}
});
答案 0 :(得分:2)
在这种情况下,它总是建议使用switch case,你应该返回true以阻止其他操作
switch(event.getAction()){
case MotionEvent.ACTION_MOVE: Log.e("touchtest", "ACTION_MOVE");
return true;
case MotionEvent.ACTION_UP: Log.e("touchtest", "ACTION_UP");
return true;
case MotionEvent.ACTION_DOWN: Log.e("touchtest", "ACTION_DOWN");
return true;
default:
return false;
}
希望它能运作