使用switch (event.getAction())可以处理ACTION_DOWN和ACTION_UP事件
使用switch (event.getAction() & MotionEvent.ACTION_MASK)就可以处理处理多点触摸的ACTION_POINTER_DOWN和ACTION_POINTER_UP事件
ACTION_DOWN和ACTION_UP就是单点触摸屏幕,按下去和放开的操作; ACTION_POINTER_DOWN和ACTION_POINTER_UP就是多点触摸屏幕,当有一只手指按下去的时候,另一只手指按下和放开的动作捕捉; ACTION_MOVE就是手指在屏幕上移动的操作
附上一图片类似布卡漫画图片放大的代码
@Override
public boolean onTouchEvent(MotionEvent event)
{
int pointcount = event.getPointerCount();
F.out("pointcount=" + pointcount);
if (pointcount == 1)
{
if (!PlayerActivity.this.thisActivityGesture.onTouchEvent(event))
{
}
}
if (pointcount == 2)
{
switch (event.getAction() & MotionEvent.ACTION_MASK)
{
case MotionEvent.ACTION_POINTER_DOWN:
oldDistance = (float) Math.sqrt((event.getX(0) - event.getX(1)) * (event.getX(0) - event.getX(1)) + (event.getY(0) - event.getY(1)) * (event.getY(0) - event.getY(1)));
oldpiont.set((int) (event.getX(0) + event.getX(1)) / 2, (int) (event.getY(0) + event.getY(1)) / 2);
F.out(" oldDistance=" + oldDistance);
break;
case MotionEvent.ACTION_MOVE:
float newDistance;
newDistance = (float) Math.sqrt((event.getX(0) - event.getX(1)) * (event.getX(0) - event.getX(1)) + (event.getY(0) - event.getY(1)) * (event.getY(0) - event.getY(1)));
if (newDistance > 10f)
{
F.out("newDistance=" + newDistance + " oldDistance=" + oldDistance);
if (imageView != null) imageView.scaleView(newDistance / oldDistance, oldpiont.x, oldpiont.y);
oldDistance = newDistance;
}
break;
case MotionEvent.ACTION_POINTER_UP:
oldDistance = 10;
oldpiont.set(0, 0);
break;
}
}
return false;
}
类似布卡漫画的功能,图片围绕双击的中心变大,而且还可以托动
代码:http://download.csdn.net/detail/yanglian20009/4531486