{"record":{"id":"dfd8b1d97e58443b","repo":"Baseflow/PhotoView","slug":"matrix-scale-type-is-not-supported","errorCode":null,"errorMessage":"Matrix scale type is not supported","messagePattern":"Matrix scale type is not supported","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"photoview/src/main/java/com/github/chrisbanes/photoview/Util.java","lineNumber":29,"sourceCode":"            throw new IllegalArgumentException(\n                    \"Minimum zoom has to be less than Medium zoom. Call setMinimumZoom() with a more appropriate value\");\n        } else if (midZoom >= maxZoom) {\n            throw new IllegalArgumentException(\n                    \"Medium zoom has to be less than Maximum zoom. Call setMaximumZoom() with a more appropriate value\");\n        }\n    }\n\n    static boolean hasDrawable(ImageView imageView) {\n        return imageView.getDrawable() != null;\n    }\n\n    static boolean isSupportedScaleType(final ImageView.ScaleType scaleType) {\n        if (scaleType == null) {\n            return false;\n        }\n        switch (scaleType) {\n            case MATRIX:\n                throw new IllegalStateException(\"Matrix scale type is not supported\");\n        }\n        return true;\n    }\n\n    static int getPointerIndex(int action) {\n        return (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;\n    }\n}\n","sourceCodeStart":11,"sourceCodeEnd":38,"githubUrl":"https://github.com/Baseflow/PhotoView/blob/565505d5cb84f5977771b5d2ccb7726338e77224/photoview/src/main/java/com/github/chrisbanes/photoview/Util.java#L11-L38","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Remove the setScaleType(MATRIX) call and let PhotoView manage its own matrix; use its setDisplayMatrix/getDisplayMatrix API for custom transforms instead.","For shared helpers, special-case the view: if (!(view instanceof PhotoView)) view.setScaleType(scaleType).","In XML, change android:scaleType on the PhotoView to fit_center/fitXY etc., or delete the attribute entirely."],"exampleFix":"// before\nimageView.setScaleType(ImageView.ScaleType.MATRIX); // crashes if imageView is a PhotoView\n\n// after\nif (imageView instanceof PhotoView) {\n    // let PhotoView control its own matrix; apply custom transforms via:\n    Matrix m = new Matrix();\n    ((PhotoView) imageView).getDisplayMatrix(m);\n    ((PhotoView) imageView).setDisplayMatrix(m);\n} else {\n    imageView.setScaleType(ImageView.ScaleType.MATRIX);\n}","handlingStrategy":"type-guard","validationCode":"if (imageView instanceof PhotoView) {\n    // PhotoView manages its own matrix; do not call setScaleType(MATRIX)\n} else {\n    imageView.setScaleType(ImageView.ScaleType.MATRIX);\n}","typeGuard":"private static boolean isPhotoView(ImageView view) {\n    return view instanceof com.github.chrisbanes.photoview.PhotoView;\n}\n\nprivate static boolean isSafeScaleType(ImageView view, ImageView.ScaleType st) {\n    return !(view instanceof com.github.chrisbanes.photoview.PhotoView)\n        || st != ImageView.ScaleType.MATRIX;\n}","tryCatchPattern":null,"preventionTips":["Never call setScaleType(MATRIX) on a PhotoView — use setDisplayMatrix for custom transforms.","Audit shared image-loading/binding helpers for blanket setScaleType calls applied to every ImageView.","In XML layouts, omit scaleType on PhotoView or use a supported non-MATRIX value."],"tags":["photoview","android","scaletype","matrix","illegalstateexception","imageview"],"backgroundTag":null,"analyzedSha":"565505d5cb84f5977771b5d2ccb7726338e77224","analyzedAt":"2026-08-14T14:25:26.552Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}