{"record":{"id":"f7cec3df01704e80","repo":"material-components/material-components-android","slug":"appbarlayout-is-always-vertical-and-does-not-suppo","errorCode":null,"errorMessage":"AppBarLayout is always vertical and does not support horizontal orientation","messagePattern":"AppBarLayout is always vertical and does not support horizontal orientation","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/appbar/AppBarLayout.java","lineNumber":744,"sourceCode":"            ? null\n            : behavior.saveScrollState(AbsSavedState.EMPTY_STATE, this);\n    // Invalidate the scroll ranges\n    totalScrollRange = INVALID_SCROLL_RANGE;\n    downPreScrollRange = INVALID_SCROLL_RANGE;\n    downScrollRange = INVALID_SCROLL_RANGE;\n    // Restores the previous scrolling state. Don't override if there's a previously saved state\n    // which has not be restored yet. Multiple re-measuring can happen before the scroll state\n    // is actually restored. We don't want to restore the state in-between those re-measuring,\n    // since they can be incorrect.\n    if (savedState != null) {\n      behavior.restoreScrollState(savedState, false);\n    }\n  }\n\n  @Override\n  public void setOrientation(int orientation) {\n    if (orientation != VERTICAL) {\n      throw new IllegalArgumentException(\n          \"AppBarLayout is always vertical and does not support horizontal orientation\");\n    }\n    super.setOrientation(orientation);\n  }\n\n  @Override\n  protected void onAttachedToWindow() {\n    super.onAttachedToWindow();\n\n    MaterialShapeUtils.setParentAbsoluteElevation(this);\n  }\n\n  @Override\n  @NonNull\n  public CoordinatorLayout.Behavior<AppBarLayout> getBehavior() {\n    behavior = new AppBarLayout.Behavior();\n    return behavior;\n  }","sourceCodeStart":726,"sourceCodeEnd":762,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/appbar/AppBarLayout.java#L726-L762","documentation":"AppBarLayout extends LinearLayout but overrides setOrientation to lock the orientation to VERTICAL, because its scrolling behavior and layout logic only support vertical children. Any attempt to set HORIZONTAL (or any non-vertical value) throws IllegalArgumentException immediately.","triggerScenarios":"Calling appBarLayout.setOrientation(LinearLayout.HORIZONTAL); setting android:orientation=\"horizontal\" in XML on an AppBarLayout; or programmatically applying a generic orientation constant that is not VERTICAL.","commonSituations":"Treating AppBarLayout as a normal LinearLayout; copying a horizontal LinearLayout layout block and changing the tag to AppBarLayout; code that calls setOrientation based on a configuration flag that evaluates to HORIZONTAL.","solutions":["Remove the setOrientation call or use setOrientation(LinearLayout.VERTICAL).","Remove android:orientation=\"horizontal\" from the AppBarLayout XML tag (vertical is the default).","If you truly need horizontal arrangement, use a LinearLayout or other horizontal container inside or instead of AppBarLayout."],"exampleFix":"<!-- before -->\n<com.google.android.material.appbar.AppBarLayout\n    android:orientation=\"horizontal\"\n    ... />\n\n<!-- after -->\n<com.google.android.material.appbar.AppBarLayout ... />\n<!-- default orientation is vertical; arrange children in a horizontal LinearLayout if needed -->","handlingStrategy":"validation","validationCode":"int orientation = LinearLayout.VERTICAL; // AppBarLayout only accepts vertical\nif (orientation == LinearLayout.VERTICAL) {\n  appBarLayout.setOrientation(orientation);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Lint for android:orientation on AppBarLayout in CI.","Treat AppBarLayout as a vertical-only container in design reviews."],"tags":["appbar","layout","illegal-argument","xml-configuration"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}