Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reset zoom? #6

Open
sashafiero opened this issue Oct 18, 2017 · 5 comments
Open

How to reset zoom? #6

sashafiero opened this issue Oct 18, 2017 · 5 comments

Comments

@sashafiero
Copy link

I can't figure out how to reset the zoom level. I am using one ImageView, into which I am loading one image at a time (from a thumbnail) for zooming with. However, if I open one, zoom in a bit, close it (hiding the imageview), then open another image, it shows up at the same zoom level as the one before it.

I tried setting a new ImageMatrixTouchHandler on the zoomed in ImageView every time I load in a new pic, but that didn't help.

I also tried making a "standalone" ImageMatrixTouchHandler ahead of setting it on the ImageView, with the thought that I could try myImageMatrixTouchHandler.animateZoom(0, 0) but I get a
Attempt to invoke virtual method 'void android.graphics.Matrix.getValues(float[])' on a null object reference

@martinwithaar
Copy link
Owner

You could try setting an identity matrix to the ImageView like so:

imageView.setImageMatrix(new Matrix());
imageView.invalidate();

This would reset all transforms on the image such as scaling and translations. I am not sure if the last row is required for the view to update properly. You should try it out yourself.

@sashafiero
Copy link
Author

Unfortunately, that gave other problems. Load a photo into the zoomable ImageView, zoom it, close it. Open another, and it's fit to the space, but you can't zoom it at all. Also, where normally a landscape photo is centered vertically, the "broken" ones are at the top of the space.

I simplified everything as much as I could in a test version, and I've ended up just making a new ImageView to hold the zoomable full screen image, and removing it entirely when the zoomed image is closed.

@ndubbaka
Copy link

I have the same issue as @sashafiero

Until we find a real solution, I followed what @sashafiero did with "making a new ImageView"

                ViewGroup.LayoutParams lParams = ivImage.getLayoutParams();
                imageParentLayout.removeView(ivImage);
                ivImage = new ImageView(this);
                ivImage.setLayoutParams(lParams);
                imageParentLayout.addView(ivImage);

@vladislav1nikov
Copy link

My solution to this problem:
imageView.setImageMatrix(new Matrix());
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

@VivekThummar52
Copy link

@vladislav1nikov Thanks for the solution, it worked for me..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants