在所有android设备中,手机这种允许拖拽,复杂放大缩小手势的不多。但在有些时候或许用的到。这里稍作记录。

OnTouchListener的onTouch(event),这个MotionEvent里面包含了所有的触控存在的操作。

单点触控过程:

MotionEvent.ACTION_DOWN(按下)-MotionEvent.ACTION_MOVE(移动)-MotionEvent.ACTION_UP(抬起)/MotionEvent.ACTION_CANCEL(超出边界)

多点触控过程:

此时action变化:

int action = event.getAction() & MotionEvent.ACTION_MASK;
MotionEvent.ACTION_DOWN(按下)-MotionEvent.ACTION_POINTER_DOWN(除第一个手指外新按下手指)-MotionEvent.ACTION_MOVE(所有手指移动)-MotionEvent.ACTION_POINTER_UP(非第一个手指抬起)-MotionEvent.ACTION_UP(抬起)/MotionEvent.ACTION_CANCEL(超出边界)

第几个按下的手指进行操作:

event.getAction() >> 8

另多点获取位置:

新点位置:

event.getX(1);
event.getY(1);

新点获取位置index:

index = event.getActionIndex();
mNewLastX = event.getX(index);
mNewLastY = event.getY(index);

pointerId:

获取方式

event.getPointerId(event.getActionIndex());

pointerId是固定值.actionindex是变化值
如你按下第一个手指时,id=0,index=0
按下第二个手指时,id=1,index=1
抬起第一个手指时,剩余手指:id=1,index=0

参考博客:
​​​https://www.jianshu.com/p/3eca050b90ed​