{"record":{"id":"1e181300cf05dc23","repo":"umano/AndroidSlidingUpPanel","slug":"width-must-have-an-exact-value-or-match-parent","errorCode":null,"errorMessage":"Width must have an exact value or MATCH_PARENT","messagePattern":"Width must have an exact value or MATCH_PARENT","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/sothree/slidinguppanel/SlidingUpPanelLayout.java","lineNumber":732,"sourceCode":"        super.onAttachedToWindow();\n        mFirstLayout = true;\n    }\n\n    @Override\n    protected void onDetachedFromWindow() {\n        super.onDetachedFromWindow();\n        mFirstLayout = true;\n    }\n\n    @Override\n    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\n        final int widthMode = MeasureSpec.getMode(widthMeasureSpec);\n        final int widthSize = MeasureSpec.getSize(widthMeasureSpec);\n        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);\n        final int heightSize = MeasureSpec.getSize(heightMeasureSpec);\n\n        if (widthMode != MeasureSpec.EXACTLY && widthMode != MeasureSpec.AT_MOST) {\n            throw new IllegalStateException(\"Width must have an exact value or MATCH_PARENT\");\n        } else if (heightMode != MeasureSpec.EXACTLY && heightMode != MeasureSpec.AT_MOST) {\n            throw new IllegalStateException(\"Height must have an exact value or MATCH_PARENT\");\n        }\n\n        final int childCount = getChildCount();\n\n        if (childCount != 2) {\n            throw new IllegalStateException(\"Sliding up panel layout must have exactly 2 children!\");\n        }\n\n        mMainView = getChildAt(0);\n        mSlideableView = getChildAt(1);\n        if (mDragView == null) {\n            setDragView(mSlideableView);\n        }\n\n        // If the sliding panel is not visible, then put the whole view in the hidden state\n        if (mSlideableView.getVisibility() != VISIBLE) {","sourceCodeStart":714,"sourceCodeEnd":750,"githubUrl":"https://github.com/umano/AndroidSlidingUpPanel/blob/45a460435b07e764138a700328836cafc1ed5c42/library/src/main/java/com/sothree/slidinguppanel/SlidingUpPanelLayout.java#L714-L750","documentation":"During onMeasure, SlidingUpPanelLayout requires its width measure spec to be EXACTLY or AT_MOST. If the parent measures it UNSPECIFIED (e.g. wrap_content inside certain parents), it throws IllegalStateException because panel positioning math needs a concrete width.","triggerScenarios":"Laying out SlidingUpPanelLayout with wrap_content width inside a parent that generates UNSPECIFIED/loose specs, or placing it in containers like ScrollView/LinearLayout with wrap_content that don't provide exact bounds.","commonSituations":"XML layout where the SlidingUpPanelLayout root has layout_width=\"wrap_content\", or embedding it in a horizontally scrolling container.","solutions":["Set layout_width to match_parent or a fixed dp value in XML","If programmatic, measure with MeasureSpec.EXACTLY or AT_MOST","Remove wrapping scroll containers that don't impose a bounded width"],"exampleFix":"// before\n<com.sothree.slidinguppanel.SlidingUpPanelLayout\n    android:layout_width=\"wrap_content\" ... />\n// after\n<com.sothree.slidinguppanel.SlidingUpPanelLayout\n    android:layout_width=\"match_parent\" ... />","handlingStrategy":"validation","validationCode":"ViewGroup.LayoutParams lp = layout.getLayoutParams();\nif (lp != null && lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) lp.width = ViewGroup.LayoutParams.MATCH_PARENT;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use match_parent or fixed dp width for SlidingUpPanelLayout","Avoid wrapping in unbounded-width containers","Lint-check layouts that use wrap_content on this root"],"tags":["android","layout","measure-spec"],"backgroundTag":"invalid-config-value","analyzedSha":"45a460435b07e764138a700328836cafc1ed5c42","analyzedAt":"2026-09-11T10:02:33.403Z","contentChangedAt":"2026-09-11T10:02:33.403Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}