{"record":{"id":"b1ba03b1964dd923","repo":"material-components/material-components-android","slug":"the-wrap-overflow-mode-is-not-compatible-to-the-ve","errorCode":null,"errorMessage":"The wrap overflow mode is not compatible to the vertical orientation.","messagePattern":"The wrap overflow mode is not compatible to the vertical orientation\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/button/MaterialButtonGroup.java","lineNumber":382,"sourceCode":"  @NonNull\n  public ShapeAppearanceModel getChildOriginalShapeAppearanceModel(int index) {\n    return originalChildShapeAppearanceModels.get(index).getDefaultShape();\n  }\n\n  private void recoverAllChildrenLayoutParams() {\n    for (int i = 0; i < getChildCount(); i++) {\n      MaterialButton child = getChildButton(i);\n      child.recoverOriginalLayoutParams();\n    }\n  }\n\n  @Override\n  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\n    adjustChildMarginsAndUpdateLayout();\n    int wrappedHeight = 0;\n    if (overflowMode == OVERFLOW_MODE_WRAP) {\n      if (getOrientation() == VERTICAL) {\n        throw new IllegalArgumentException(\n            \"The wrap overflow mode is not compatible to the vertical orientation.\");\n      }\n      if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.AT_MOST) {\n        throw new IllegalArgumentException(\n            \"The wrap overflow mode is not compatible with wrap_content layout width.\");\n      }\n      wrappedHeight = maybeWrapButtons(widthMeasureSpec, heightMeasureSpec);\n    }\n    maybeUpdateOverflowMenu(widthMeasureSpec, heightMeasureSpec);\n    updateChildShapes();\n    super.onMeasure(widthMeasureSpec, heightMeasureSpec);\n    if (overflowMode == OVERFLOW_MODE_WRAP && wrappedHeight != getMeasuredHeight()) {\n      setMeasuredDimension(getMeasuredWidth(), wrappedHeight);\n    }\n  }\n\n  @Override\n  protected void onLayout(boolean changed, int l, int t, int r, int b) {","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/button/MaterialButtonGroup.java#L364-L400","documentation":"MaterialButtonGroup (the flow/overflow-aware button group) supports an OVERFLOW_MODE_WRAP mode in which buttons that do not fit horizontally wrap onto additional rows. Wrapping only makes sense for horizontal groups: in onMeasure (MaterialButtonGroup.java:382) a vertical orientation with wrap overflow throws IllegalArgumentException, because 'wrapping' a vertical column of buttons has no defined meaning and would break the group's child-shape stitching and overflow-menu logic.","triggerScenarios":"Setting app:overflowMode=\"wrap\" (or setOverflowMode(OVERFLOW_MODE_WRAP)) on a MaterialButtonGroup whose orientation is vertical (XML app:orientation=\"vertical\" or setOrientation(VERTICAL)). The check runs inside onMeasure, so the exception is thrown at layout time, not at attribute-set time.","commonSituations":"Copying a horizontal wrap-mode button row from a demo and flipping it to vertical without removing the wrap overflow mode. Toggling orientation at runtime based on screen size while leaving overflowMode=wrap. Because the throw happens in onMeasure, the stack trace points at layout/inflation rather than the misconfigured attribute, which confuses developers.","solutions":["Use a different overflow mode for vertical groups — keep the default OVERFLOW_MODE_OVERFLOW (overflow menu) or whatever non-wrap value fits — i.e. remove app:overflowMode=\"wrap\".","Keep the group horizontal if you need wrapping; vertical wrapping layouts are better expressed by FlexboxLayout or a Flow helper.","If orientation is switched at runtime, call setOverflowMode back to a compatible value before changing orientation."],"exampleFix":"<!-- before -->\n<com.google.android.material.button.MaterialButtonGroup\n    app:orientation=\"vertical\"\n    app:overflowMode=\"wrap\" />\n\n<!-- after -->\n<com.google.android.material.button.MaterialButtonGroup\n    app:orientation=\"vertical\" />","handlingStrategy":"validation","validationCode":"if (group.getOrientation() == LinearLayout.HORIZONTAL) {\n  group.setOverflowMode(MaterialButtonGroup.OVERFLOW_MODE_WRAP);\n} else {\n  group.setOverflowMode(MaterialButtonGroup.OVERFLOW_MODE_OVERFLOW);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat wrap overflow as horizontal-only by convention in your codebase.","When switching orientation at runtime, reset overflowMode first.","Code-review XML pairs of app:orientation and app:overflowMode together."],"tags":["android","material-components","materialbuttongroup","layout","xml-config"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}