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 show initially full image with PhotoView? #498

Open
anthony3444 opened this issue Apr 17, 2017 · 9 comments
Open

How to show initially full image with PhotoView? #498

anthony3444 opened this issue Apr 17, 2017 · 9 comments

Comments

@anthony3444
Copy link

Hi guys!
First at all, thank you very much for your awesome library! Great job!

About my problem: when my Activity starts, I want to show initially full image in PhotoView widget (like center_crop scale). It's just for initialization, so I can't set scale_type = center_crop, because after that I can't see complete image when I pinch / zoom.

thank you very much for your help!

@Thomas-Vos
Copy link

Did you find a solution?

@thealeksandr
Copy link

Looking for this feature as well

@nithinpmolethu
Copy link

Zoom out feature will be good.

@lilipu1
Copy link

lilipu1 commented Aug 12, 2017

Did you find a solution?

@anthony3444
Copy link
Author

anthony3444 commented Aug 12, 2017

Yes:

public void showFullScreen() {
        float photoViewWidth = mPhotoView.getWidth();
        float photoViewHeight = mPhotoView.getHeight();

        float viewScale = mPhotoView.getScale();
        RectF rect = mPhotoView.getDisplayRect();

        // Compute initial base rect
        float baseRectWidth = (rect.right - rect.left) / viewScale;
        float baseRectHeight = (rect.bottom - rect.top) / viewScale;

        // Compute medium scale for full size
        double mediumScale, currentScale;
        if (baseRectHeight > baseRectWidth) {
            mediumScale = photoViewWidth / baseRectWidth;
        } else {
            mediumScale = photoViewHeight / baseRectHeight;
        }

        mediumScale = Math.round(mediumScale * 100.0) / 100.0;
        currentScale = Math.round(mPhotoView.getScale() * 100.0) / 100.0;

        // Apply new scale: minimum or medium
        if (currentScale < mediumScale) {
            mPhotoView.setScale((float) mediumScale);

        } else {
            mPhotoView.setScale(mPhotoView.getMinimumScale());
        }
    }

@giusecapo
Copy link

@anthony3444 I tried your solution but got nothing. When I call photoView.setScale(something) nothing changes. Do you know why?

@tronious
Copy link

tronious commented Jul 18, 2018

@giusecapo if this is not working for you try setting the scale AFTER the view renders:

Example:

    dashboard_image = (PhotoView) TheView.findViewById(R.id.dashboard_image);

    ViewTreeObserver vto = dashboard_image.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            dashboard_image.getViewTreeObserver().removeOnGlobalLayoutListener(this);

            dashboard_image.setScale(2f);
        }
    });

@shakeri-mreza
Copy link

@anthony3444
solution works more or less. but sometimes causes throwing :

java.lang.IllegalArgumentException: Medium zoom has to be less than Maximum zoom. Call setMaximumZoom() with a more appropriate value

@yudikarma
Copy link

just add this in your xml photoview

android:adjustViewBounds="true" android:scaleType="fitXY"

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

9 participants