在ViewGroup中缩放ImageView

时间:2011-07-22 07:56:04

标签: android imageview zoom viewgroup

我在ViewGroup中有不同的ImageView。每个ImageView都有这样的onTouch事件:

      public boolean onTouch(View v,MotionEvent event){
      ImageView view = (ImageView)v;

      // Dump touch event to log
      dumpEvent(event);

      // Handle touch events here...
      switch (event.getAction() & MotionEvent.ACTION_MASK )
      {
          case MotionEvent.ACTION_DOWN:

              savedMatrix.set(matrix);
              start.set(event.getX(), event.getY());
              Log.d(TAG, "mode=DRAG");
              mode = DRAG;

              break;
          case MotionEvent.ACTION_UP:
          case MotionEvent.ACTION_POINTER_UP:
              mode = NONE;
              Log.d(TAG, "mode=NONE");
              break;
          case MotionEvent.ACTION_POINTER_DOWN:
              oldDist = spacing(event);
              Log.d(TAG, "oldDist=" + oldDist);
              if (oldDist > 10f)
              {
                  savedMatrix.set(matrix);
                  midPoint(mid, event);
                  mode = ZOOM;
                  Log.d(TAG, "mode=ZOOM");
              }
              break;
          case MotionEvent.ACTION_MOVE:
              if (mode == DRAG)
              {
                  matrix.set(savedMatrix);
                  matrix.postTranslate(event.getX() - start.x, event.getY() - start.y);
              }
              else if (mode == ZOOM)
              {
                  float newDist = spacing(event);
                  Log.d(TAG, "newDist=" + newDist);
                  if (newDist > 10f)
                  {
                      matrix.set(savedMatrix);
                      float scale = newDist / oldDist;
                      matrix.postScale(scale, scale, mid.x, mid.y);
                  }
              }
              break;
      }
      Log.d(TAG, "setting matrix " + matrix);
      view.setImageMatrix(matrix);

      return true; // Indicate event was handled
  }

在logcat中,我看到onTouch事件已经处理但没有任何反应。 在ViewGroup中,我使用InterceptTouchEvent来拖动ImageView并移动像android主屏幕一样的滑动视图。

我认为在用于缩放的dispacth触摸事件上ViewGroup和ImageView之间存在问题,或者ViewGroup有一个特定的设置。有人能告诉我是否可以放大ViewGroup的子项内部以及如何实现它?

0 个答案:

没有答案