Baseflow/PhotoView · error · IllegalStateException

Matrix scale type is not supported

Error message

Matrix scale type is not supported

What it means

PhotoView deliberately refuses ImageView.ScaleType.MATRIX with an IllegalStateException from Util.isSupportedScaleType, reached via PhotoView.setScaleType or the attacher's update path. PhotoView manipulates its own internal android.graphics.Matrix (draw matrix + supplementary matrix) to implement pinch-zoom, so an external MATRIX scale type would conflict with the attacher's matrix math. Unlike the IllegalArgumentExceptions in this library, this is a state/usage error: no Matrix-based input can ever be accepted.

Source

Thrown at photoview/src/main/java/com/github/chrisbanes/photoview/Util.java:29

            throw new IllegalArgumentException(
                    "Minimum zoom has to be less than Medium zoom. Call setMinimumZoom() with a more appropriate value");
        } else if (midZoom >= maxZoom) {
            throw new IllegalArgumentException(
                    "Medium zoom has to be less than Maximum zoom. Call setMaximumZoom() with a more appropriate value");
        }
    }

    static boolean hasDrawable(ImageView imageView) {
        return imageView.getDrawable() != null;
    }

    static boolean isSupportedScaleType(final ImageView.ScaleType scaleType) {
        if (scaleType == null) {
            return false;
        }
        switch (scaleType) {
            case MATRIX:
                throw new IllegalStateException("Matrix scale type is not supported");
        }
        return true;
    }

    static int getPointerIndex(int action) {
        return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    }
}

View on GitHub (pinned to 565505d5cb)

Solutions

  1. Remove the setScaleType(MATRIX) call and let PhotoView manage its own matrix; use its setDisplayMatrix/getDisplayMatrix API for custom transforms instead.
  2. For shared helpers, special-case the view: if (!(view instanceof PhotoView)) view.setScaleType(scaleType).
  3. In XML, change android:scaleType on the PhotoView to fit_center/fitXY etc., or delete the attribute entirely.

Example fix

// before
imageView.setScaleType(ImageView.ScaleType.MATRIX); // crashes if imageView is a PhotoView

// after
if (imageView instanceof PhotoView) {
    // let PhotoView control its own matrix; apply custom transforms via:
    Matrix m = new Matrix();
    ((PhotoView) imageView).getDisplayMatrix(m);
    ((PhotoView) imageView).setDisplayMatrix(m);
} else {
    imageView.setScaleType(ImageView.ScaleType.MATRIX);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (imageView instanceof PhotoView) {
    // PhotoView manages its own matrix; do not call setScaleType(MATRIX)
} else {
    imageView.setScaleType(ImageView.ScaleType.MATRIX);
}

Type guard

private static boolean isPhotoView(ImageView view) {
    return view instanceof com.github.chrisbanes.photoview.PhotoView;
}

private static boolean isSafeScaleType(ImageView view, ImageView.ScaleType st) {
    return !(view instanceof com.github.chrisbanes.photoview.PhotoView)
        || st != ImageView.ScaleType.MATRIX;
}

Prevention

When it happens

Trigger: Calling photoView.setScaleType(ImageView.ScaleType.MATRIX) on a PhotoView; calling setScaleType with a scale type read from a shared XML attr or constants table that includes MATRIX; wrapping a PhotoView in code that generically configures ImageViews (e.g. a shared image-loading helper) and applies MATRIX to every ImageView it touches.

Common situations: Shared image-binding utilities (Glide/Picasso wrappers or RecyclerView bind helpers) that call setScaleType on any ImageView, breaking when the view is a PhotoView; migrating code from a plain ImageView that used MATRIX + custom matrix transforms; XML layouts where app:scaleType or android:scaleType="matrix" is applied to a com.github.chrisbanes.photoview.PhotoView (the attacher overrides/throws during update).

Related errors


AI-assisted analysis of Baseflow/PhotoView@565505d5cb (2026-08-14). Data as JSON: /api/errors/dfd8b1d97e58443b. Report an issue: GitHub.