{"record":{"id":"97b4b99847ca8c6a","repo":"jfeinstein10/SlidingMenu","slug":"cannot-set-both-behindoffset-and-behindwidth-for-a","errorCode":null,"errorMessage":"Cannot set both behindOffset and behindWidth for a SlidingMenu","messagePattern":"Cannot set both behindOffset and behindWidth for a SlidingMenu","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java","lineNumber":258,"sourceCode":"\t\t\tsetContent(viewAbove);\n\t\t} else {\n\t\t\tsetContent(new FrameLayout(context));\n\t\t}\n\t\tint viewBehind = ta.getResourceId(R.styleable.SlidingMenu_viewBehind, -1);\n\t\tif (viewBehind != -1) {\n\t\t\tsetMenu(viewBehind); \n\t\t} else {\n\t\t\tsetMenu(new FrameLayout(context));\n\t\t}\n\t\tint touchModeAbove = ta.getInt(R.styleable.SlidingMenu_touchModeAbove, TOUCHMODE_MARGIN);\n\t\tsetTouchModeAbove(touchModeAbove);\n\t\tint touchModeBehind = ta.getInt(R.styleable.SlidingMenu_touchModeBehind, TOUCHMODE_MARGIN);\n\t\tsetTouchModeBehind(touchModeBehind);\n\n\t\tint offsetBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindOffset, -1);\n\t\tint widthBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindWidth, -1);\n\t\tif (offsetBehind != -1 && widthBehind != -1)\n\t\t\tthrow new IllegalStateException(\"Cannot set both behindOffset and behindWidth for a SlidingMenu\");\n\t\telse if (offsetBehind != -1)\n\t\t\tsetBehindOffset(offsetBehind);\n\t\telse if (widthBehind != -1)\n\t\t\tsetBehindWidth(widthBehind);\n\t\telse\n\t\t\tsetBehindOffset(0);\n\t\tfloat scrollOffsetBehind = ta.getFloat(R.styleable.SlidingMenu_behindScrollScale, 0.33f);\n\t\tsetBehindScrollScale(scrollOffsetBehind);\n\t\tint shadowRes = ta.getResourceId(R.styleable.SlidingMenu_shadowDrawable, -1);\n\t\tif (shadowRes != -1) {\n\t\t\tsetShadowDrawable(shadowRes);\n\t\t}\n\t\tint shadowWidth = (int) ta.getDimension(R.styleable.SlidingMenu_shadowWidth, 0);\n\t\tsetShadowWidth(shadowWidth);\n\t\tboolean fadeEnabled = ta.getBoolean(R.styleable.SlidingMenu_fadeEnabled, true);\n\t\tsetFadeEnabled(fadeEnabled);\n\t\tfloat fadeDeg = ta.getFloat(R.styleable.SlidingMenu_fadeDegree, 0.33f);\n\t\tsetFadeDegree(fadeDeg);","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/jfeinstein10/SlidingMenu/blob/4254feca3ece9397cd501921ee733f19ea0fdad8/library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java#L240-L276","documentation":"When inflating SlidingMenu from XML, the attributes behindOffset and behindWidth are mutually exclusive: the behind view's size is defined either as a fixed offset from the edge or an explicit width, never both. If both are set in the layout's styleable, the constructor throws IllegalStateException.","triggerScenarios":"Declaring both app:behindOffset and app:behindWidth on a <com.jeremyfeinstein.slidingmenu.lib.SlidingMenu> element in a layout XML, both resolving to values other than -1.","commonSituations":"Merging styles/themes that each set one of the two attributes; copy-pasting an example layout that already had behindOffset and then adding behindWidth; defaulting both in a style.","solutions":["Remove either app:behindOffset or app:behindWidth from the XML declaration","Keep behindOffset for margin-based layout or behindWidth for fixed-width menu","Set one of them programmatically via setBehindOffset()/setBehindWidth() instead of XML"],"exampleFix":"// before (XML)\napp:behindOffset=\"100dp\"\napp:behindWidth=\"300dp\"\n// after (XML)\napp:behindOffset=\"100dp\"","handlingStrategy":"validation","validationCode":"// ensure only one of the two attributes is present in the style/attr set\nif (hasBehindOffset && hasBehindWidth) throw new IllegalStateException(\"set only behindOffset OR behindWidth\");","typeGuard":null,"tryCatchPattern":"try { slidingMenu = new SlidingMenu(context, attrs); } catch (IllegalStateException e) { slidingMenu = new SlidingMenu(context); slidingMenu.setBehindOffset(offsetPx); }","preventionTips":["Pick one sizing strategy (offset vs width) per project and stick to it","Audit merged styles/themes for duplicate attribute definitions","Prefer programmatic configuration to avoid XML attribute merging surprises"],"tags":["android","slidingmenu","xml-config","conflicting-options"],"backgroundTag":"conflicting-config-options","analyzedSha":"4254feca3ece9397cd501921ee733f19ea0fdad8","analyzedAt":"2026-09-09T10:08:27.041Z","contentChangedAt":"2026-09-09T10:08:27.041Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}