Photoview: PhotoViewで最初に完全な画像を表示するにはどうすればよいですか?

作成日 2017年04月17日  ·  9コメント  ·  ソース: Baseflow/PhotoView

こんにちは、みんな!
まず第一に、あなたの素晴らしいライブラリをどうもありがとう! よくやった!

私の問題について:アクティビティの開始時に、最初はPhotoViewウィジェットに完全な画像(center_cropスケールなど)を表示したいと思います。 初期化のためだけなので、scale_type = center_cropを設定できません。これは、その後、ピンチ/ズームしたときに完全な画像が表示されないためです。

手伝ってくれてありがとうございます!

最も参考になるコメント

はい:

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());
        }
    }

全てのコメント9件

解決策を見つけましたか?

この機能も探しています

ズームアウト機能が良いでしょう。

解決策を見つけましたか?

はい:

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());
        }
    }

@ anthony3444私はあなたの解決策を試しましたが、何も得られませんでした。 photoView.setScale(something)を呼び出しても、何も変わりません。 なぜなのかご存知ですか?

@giusecapoこれが機能しない場合は、ビューがレンダリングされた後にスケールを設定してみてください。

例:

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

    ViewTreeObserver vto = dashboard_image.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        <strong i="8">@Override</strong>
        public void onGlobalLayout() {
            dashboard_image.getViewTreeObserver().removeOnGlobalLayoutListener(this);

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

@ anthony3444
ソリューションは多かれ少なかれ機能します。 しかし時々投げを引き起こします:

java.lang.IllegalArgumentException:中ズームは最大ズームより小さくする必要があります。 より適切な値でsetMaximumZoom()を呼び出します

これをxmlフォトビューに追加するだけです

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

このページは役に立ちましたか?
0 / 5 - 0 評価