Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6592879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:36:41+00:00 2026-05-25T17:36:41+00:00

So I have an ImageView using a Matrix to scale the Bitmap I’m displaying.

  • 0

So I have an ImageView using a Matrix to scale the Bitmap I’m displaying. I can double-tap to zoom to full-size, and my ScaleAnimation handles animating the zoom-in, it all works fine.

Now I want to double-tap again to zoom out, but when I animate this with ScaleAnimation, the ImageView does not draw the newly exposed areas of the image (as the current viewport shrinks), instead you see the portion of visible image shrinking in. I have tried using ViewGroup.setClipChildren(false), but this only leaves the last-drawn artifacts from the previous frame – leading to an trippy telescoping effect, but not quite what I was after.

I know there are many zoom-related questions, but none cover my situation – specifically animating the zoom-out operation. I do have the mechanics working – ie aside from the zoom-out animation, double-tapping to zoom in and out works fine.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:36:42+00:00Added an answer on May 25, 2026 at 5:36 pm

    In the end I decided to stop using the Animation classes offered by Android, because the ScaleAnimation applies a scale to the ImageView as a whole which then combines with the scale of the ImageView’s image Matrix, making it complicated to work with (aside from the clipping issues I was having).
    Since all I really need is to animate the changes made to the ImageView’s Matrix, I implemented the OnDoubleTapListener (at the end of this post – I leave it as an “exercise to the reader” to add the missing fields and methods – I use a few PointF and Matrix fields to avoid excess garbage creation). Basically the animation itself is implemented by using View.post to keep posting a Runnable that incrementally changes the ImageView’s image Matrix:

    public boolean onDoubleTap(MotionEvent e) {
            final float x = e.getX();
            final float y = e.getY();
            matrix.reset();
            matrix.set(imageView.getImageMatrix());
            matrix.getValues(matrixValues);
            matrix.invert(inverseMatrix);
            doubleTapImagePoint[0] = x;
            doubleTapImagePoint[1] = y;
            inverseMatrix.mapPoints(doubleTapImagePoint);
            final float scale = matrixValues[Matrix.MSCALE_X];
            final float targetScale = scale < 1.0f ? 1.0f : calculateFitToScreenScale();
            final float finalX;
            final float finalY;
            // assumption: if targetScale is less than 1, we're zooming out to fit the screen
            if (targetScale < 1.0f) {
                // scaling the image to fit the screen, we want the resulting image to be centred. We need to take
                // into account the shift that is applied to zoom on the tapped point, easiest way is to reuse
                // the transformation matrix.
                RectF imageBounds = new RectF(imageView.getDrawable().getBounds());
                // set up matrix for target 
                matrix.reset();
                matrix.postTranslate(-doubleTapImagePoint[0], -doubleTapImagePoint[1]);
                matrix.postScale(targetScale, targetScale);
                matrix.mapRect(imageBounds);
    
                finalX = ((imageView.getWidth() - imageBounds.width()) / 2.0f) - imageBounds.left;
                finalY = ((imageView.getHeight() - imageBounds.height()) / 2.0f) - imageBounds.top;
            } 
            // else zoom around the double-tap point
            else {
                finalX = x;
                finalY = y;
            }
    
            final Interpolator interpolator = new AccelerateDecelerateInterpolator();
            final long startTime = System.currentTimeMillis();
            final long duration = 800;
            imageView.post(new Runnable() {
                @Override
                public void run() {
                    float t = (float) (System.currentTimeMillis() - startTime) / duration;
                    t = t > 1.0f ? 1.0f : t;
                    float interpolatedRatio = interpolator.getInterpolation(t);
                    float tempScale = scale + interpolatedRatio * (targetScale - scale);
                    float tempX = x + interpolatedRatio * (finalX - x);
                    float tempY = y + interpolatedRatio * (finalY - y);
                    matrix.reset();
                    // translate initialPoint to 0,0 before applying zoom
                    matrix.postTranslate(-doubleTapImagePoint[0], -doubleTapImagePoint[1]);
                    // zoom
                    matrix.postScale(tempScale, tempScale);
                    // translate back to equivalent point
                    matrix.postTranslate(tempX, tempY);
                    imageView.setImageMatrix(matrix);
                    if (t < 1f) {
                        imageView.post(this);
                    }
                }
            });
    
            return false;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used ImageView's before and understand the different scale types that can be
Can anyone help on how to use the matrix scaletype to zoom an imageview
I want to rotate an image using ImageView.setImageMatrix(matrix) but it simply doesn't have any
I have added an imageView of size 300*300 into the interface in my ipad
I have: String uri = @drawable/myresource.png; How can I load that in ImageView? this.setImageDrawable?
I need a way to have a gray scale image in an ImageView and
I have an ImageView with a source image set in the xml using the
I have set an image for an ImageView using the setImageResource(R.drawable.icon1) . Now my
I have an ImageView that you can use to do a one-finger pan, or
Hello i have implemented photo slideshow with scrollview and imageview using apple's scrolling example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.