3
votes

I have a code which allow user to pinch-zoom some images on the screen. I use AbsoluteLayout and imageviews to display the images. In order to achieve this, I made those imageviews have full width/height to its parent. Then when user touch a point, I will detect which image is under that point area, and use bringChildToFront() so it has focus for onTouch() event. When user make a pinch-zoom, I use matrix and its postScale() method, using this code android imageView: setting drag and pinch zoom parameters

Now, what makes me confuse is, how to get the current width/height of the image after postScale()? I've tried:

  1. getDrawable().getIntrinsicHeight() <-- didnt work. It's always return the original width/height
  2. getDrawable().getBounds().width() <-- same as above
  3. getDrawingCache().getWidth() <-- this just returns the width/height of the imageview

So, what is the appropriate way to achieve this? Thanks.

-ri

1

1 Answers

0
votes

Ri-

Here is my solution for the same problem that I had using the Pinch zoom/Drag pan. You can adapt it to your own needs. I put this inside the zoom portion of the 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);


            }

Hope that helps out.