3

我有一个代码允许用户捏缩放屏幕上的一些图像。我使用 AbsoluteLayout 和 imageviews 来显示图像。为了实现这一点,我让这些图像视图对其父级具有完整的宽度/高度。然后当用户触摸一个点时,我将检测该点区域下方的图像,并使用 bringChildToFront() 使其具有 onTouch() 事件的焦点。当用户进行捏缩放时,我使用矩阵及其 postScale() 方法,使用此代码 android imageView: setting drag and pinch zoom parameters

现在,让我感到困惑的是,如何在 postScale() 之后获取图像的当前宽度/高度?我试过了:

  1. getDrawable().getIntrinsicHeight() <--没用。它总是返回原始宽度/高度
  2. getDrawable().getBounds().width() <-- 同上
  3. getDrawingCache().getWidth()<-- 这只是返回图像视图的宽度/高度

那么,实现这一目标的适当方法是什么?谢谢。

-ri

4

1 回答 1

0

里-

这是我使用捏缩放/拖动平移时遇到的相同问题的解决方案。您可以根据自己的需要对其进行调整。我把它放在 MotionEvent.Action_Move 的缩放部分中

 else if (mode ==ZOOM){
            float newDist = spacing(event);
            if(newDist > 10f){
                int height;
                int width;
                matrix.set(savedMatrix);
                float scale = newDist/oldDist;
                matrix.postScale(scale,scale,mid.x,mid.y);
                setImageMatrix(matrix);
                height = (int)(ivViewPoint.y * scale);
                width = (int)(ivViewPoint.x * scale);
                ivViewPoint = new Point(width,height);


            }

希望能有所帮助。

于 2011-08-04T16:48:57.190 回答