事件解析
setOnTouchListener(new OnTouchListener() {});:
- 事件分发解析
MotionEvent.ACTION_DOWN:按下
MotionEvent.ACTION_MOVE:滑动
MotionEvent.ACTION_UP:抬起
使用方法
//部分区域调用需要对象:view.setOnTouchListener(new view.OnTouchListener() {})
setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()){
case MotionEvent.ACTION_UP:
//按下事件
break;
case MotionEvent.ACTION_MOVE:
//滑动事件
break;
case MotionEvent.ACTION_DOWN:
//抬起事件
break;
default:break;
}
return true;
}
});