{"record":{"id":"c75a311489ca3747","repo":"Baseflow/PhotoView","slug":"medium-zoom-has-to-be-less-than-maximum-zoom-call","errorCode":null,"errorMessage":"Medium zoom has to be less than Maximum zoom. Call setMaximumZoom() with a more appropriate value","messagePattern":"Medium zoom has to be less than Maximum zoom\\. Call setMaximumZoom\\(\\) with a more appropriate value","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"photoview/src/main/java/com/github/chrisbanes/photoview/Util.java","lineNumber":14,"sourceCode":"package com.github.chrisbanes.photoview;\n\nimport android.view.MotionEvent;\nimport android.widget.ImageView;\n\nclass Util {\n\n    static void checkZoomLevels(float minZoom, float midZoom,\n                                float maxZoom) {\n        if (minZoom >= midZoom) {\n            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    }","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/Baseflow/PhotoView/blob/565505d5cb84f5977771b5d2ccb7726338e77224/photoview/src/main/java/com/github/chrisbanes/photoview/Util.java#L1-L32","documentation":"Util.checkZoomLevels enforces minimumScale < mediumScale < maximumScale; this branch throws IllegalArgumentException when midZoom >= maxZoom, from setMediumScale, setMaximumScale, or setScaleLevels. PhotoView's double-tap handler cycles min -> mid -> max (see setScale(getMediumScale()/getMaximumScale()) in the attacher's onDoubleTap), which requires medium strictly below maximum. The check runs before assignment, so previous valid levels survive the failed call.","triggerScenarios":"Calling setMaximumScale(2f) while mediumScale is 2.0 or higher (e.g. default mid 2.0 with new max 2.0 -> 2 >= 2 throws); calling setMediumScale(3f) while max is still 3.0; setScaleLevels(1f, 2.5f, 2f) with mid above max.","commonSituations":"Lowering maximum zoom for a detail-view screen without also lowering medium; computing medium from image resolution so it exceeds a deliberately small max; setting medium before max during init and picking values that collide at equality; porting constants between screens where max was tuned per-layout but mid is a shared constant.","solutions":["Set all three at once with setScaleLevels(min, mid, max) keeping mid strictly less than max (e.g. setScaleLevels(1f, 2f, 3f)).","When lowering max, lower mid proportionally first (or in the same call): max = 2f implies mid <= something strictly below 2f, e.g. mid = max * 0.66f.","If levels are dynamic, derive them from one base: min = base, mid = base * 1.75f, max = base * 3f, so ordering can never collapse."],"exampleFix":"// before\nphotoView.setMaximumScale(1.5f); // throws: mid (2.0) >= max (1.5)\n\n// after\nphotoView.setScaleLevels(1f, 1.2f, 1.5f);","handlingStrategy":"validation","validationCode":"if (mediumScale < maximumScale\n        && minimumScale < mediumScale) {\n    photoView.setScaleLevels(minimumScale, mediumScale, maximumScale);\n} else {\n    // derive ordered levels from a single base\n    photoView.setScaleLevels(base, base * 1.75f, base * 3f);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive mid and max from one base multiplier (mid = base * 1.75f, max = base * 3f) so equality/inversion is impossible.","Review any screen that lowers maximumScale for accompanying mediumScale changes.","Cover zoom-level configuration with a unit test asserting min < mid < max for all computed inputs."],"tags":["photoview","android","zoom","validation","configuration","illegalargumentexception"],"backgroundTag":null,"analyzedSha":"565505d5cb84f5977771b5d2ccb7726338e77224","analyzedAt":"2026-08-14T14:25:26.552Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}