1
android 事件的分类:
onTouchEvent,onKey(down,up,multiple).
2
android 触摸事件 应用广泛,有两种方式使用:
(1)可以用原生的public boolean onTouchEvent(MotionEvent event);
(2)也可以用更加形象的手势处理GestureDetector;
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return mGestrueDector.onTouchEvent(event);
}
mGestrueDector = new GestureDetector(this, new MyGestureListener(this));
class MyGestureListener extends SimpleOnGestureListener 。
(2)是对(1)的某些特殊的触摸事件进行了封装。
3
有关onTouchEvent的返回值
return false
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
System.out.println("..........down 22..........");
break;
case MotionEvent.ACTION_MOVE:
System.out.println("............move. 22 .........");
break;
case MotionEvent.ACTION_UP:
System.out.println(".............up.... 22......");
break;
}
return false;
}
只能执行 ..........down 22..........
事件会继续传递。
return true
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
System.out.println("..........down 22..........");
break;
case MotionEvent.ACTION_MOVE:
System.out.println("............move. 22 .........");
break;
case MotionEvent.ACTION_UP:
System.out.println(".............up.... 22......");
break;
}
return false;
}
执行:
..........down 22..........
............move. 22 ......
.............up.... 22......
事件只在本方法中执行,不会继续传递。
代码不知道咋传。。。