rootpanthera
rootpanthera

Reputation: 2771

Zoom persist on next imageview

I've very annoying problem. Hope you can help me.

This part of my application is simple. When user taps NEXT or PREVIOUS button, imageview switches to previous or next image available. It works great but only if user does not use multitouch to ZOOM image. Please check images below to see what my problem is. I'm using TouchImageView library to zoom images.

IMAGE 1: This is image in it's normal state.

enter image description here

IMAGE 1 - ZOOM: User decides to use multitouch because it wants to ZOOM the image.

enter image description here

IMAGE 2: User taps Next button, but on the screen appears next image but it is in its ZOOMED state (from previous image).

enter image description here

Instead it should be like this:

enter image description here

Does anyone have any idea how to "reset" image and even if current picture is zoomed, next picture should not be zoomed?

Upvotes: 0

Views: 66

Answers (1)

ssantos
ssantos

Reputation: 16536

Assuming you're talking about this TouchImageView, you could add a method that wraps the logic inside

public boolean onScale(ScaleGestureDetector detector);

in a method called setScaleFactor(float scaleFactor, float focusX, floatY);

That way, onScale method would look like.-

@Override
public boolean onScale(ScaleGestureDetector detector) { 
    float mScaleFactor = detector.getScaleFactor();
    setScaleFactor(mScaleFactor, detector.getFocusX(), detector.getFocusY());

    return true;
}

And you could call

setScaleFactor(1.0f, 0.5f, 0.5f);

to 'reset' the scale.

EDIT

Assuming you're working with the TouchImageView implementation given on the link above, setScaleFactor would look like this.-

public void setScaleFactor(float mScaleFactor, float focusX, float focusY) {
    float origScale = saveScale;
    saveScale *= mScaleFactor;
    if (saveScale > maxScale) {
        saveScale = maxScale;
        mScaleFactor = maxScale / origScale;
    } else if (saveScale < minScale) {
         saveScale = minScale;
         mScaleFactor = minScale / origScale;
    }

    if (origWidth * saveScale <= viewWidth || origHeight * saveScale <= viewHeight) {
        matrix.postScale(mScaleFactor, mScaleFactor, viewWidth / 2, viewHeight / 2);
    } else {
        matrix.postScale(mScaleFactor, mScaleFactor, focusX, focusY);
    }
    fixTrans();
}

Upvotes: 1

Related Questions