android:zoom反应奇怪

时间:2012-06-19 10:37:28

标签: android zoom

我写了这个代码用于放大/缩小,它应该只用两个手指,但它适用于两个!并且通常反应奇怪!任何人都知道为什么?

boolean surfaceTouchEvent(MotionEvent event) {
  pointNum=event.getPointerCount();
  switch (event.getAction() & MotionEvent.ACTION_MASK) {
  case MotionEvent.ACTION_POINTER_DOWN:
    x1=event.getX(0);
    x2=event.getX(1);
    y1=event.getY(0);
    y2=event.getY(1);
    z4 = dist(x1, y1, x2, y2);
    println("z4 is : "+z4);
    mode = true; // pinch
    break;
  case MotionEvent.ACTION_MOVE:
    if (mode = false) {
      x3=event.getX(0)-x0;
      y3=event.getY(0)-y0;
    }  

    if (mode = true) {
      x1=event.getX(0);
      x2=event.getX(1);
      y1=event.getY(0);
      y2=event.getY(1);
      float z3 = dist(x1, y1, x2, y2);
      println("z3is :" + z3);
      if ( z3 < z4 ) { 
        zoom = z3/z4;
        println(" zoom :" + zoom);
      }
      else if ( z3 > z4) {
        zoom = z3/z4;
        println(" zoom :" + zoom);

      }
    }
    break;
  }
  return super.surfaceTouchEvent(event);
}

1 个答案:

答案 0 :(得分:0)

不知道原因,但是如果你想要用于缩放缩放的代码,那么这里是一个链接。它对我来说很好。

Android Image View Pinch Zooming