{"record":{"id":"60854a37131b43e1","repo":"material-components/material-components-android","slug":"sheet-view-has-been-laid-out-sheet-edge-cannot-be","errorCode":null,"errorMessage":"Sheet view has been laid out; sheet edge cannot be changed once the sheet has been laid out.","messagePattern":"Sheet view has been laid out; sheet edge cannot be changed once the sheet has been laid out\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/sidesheet/SheetDialog.java","lineNumber":347,"sourceCode":"    return container;\n  }\n\n  /**\n   * Set the edge which the sheet should originate from.\n   *\n   * <p>Note: This method should be called when the sheet is initialized, before it is shown.\n   * Runtime sheet edge changes are not supported.\n   *\n   * @throws IllegalStateException if the sheet is null or has already been laid out\n   * @param gravity the edge from which the sheet and its animations should originate.\n   */\n  public void setSheetEdge(@GravityInt int gravity) {\n    if (sheet == null) {\n      throw new IllegalStateException(\n          \"Sheet view reference is null; sheet edge cannot be changed if the sheet view is null.\");\n    }\n    if (sheet.isLaidOut()) {\n      throw new IllegalStateException(\n          \"Sheet view has been laid out; sheet edge cannot be changed once the sheet has been laid\"\n              + \" out.\");\n    }\n    ViewGroup.LayoutParams layoutParams = sheet.getLayoutParams();\n    if (layoutParams instanceof CoordinatorLayout.LayoutParams) {\n      ((CoordinatorLayout.LayoutParams) layoutParams).gravity = gravity;\n      maybeUpdateWindowAnimationsBasedOnLayoutDirection();\n    }\n  }\n\n  private void maybeUpdateWindowAnimationsBasedOnLayoutDirection() {\n    Window window = getWindow();\n    if (window != null\n        && sheet != null\n        && sheet.getLayoutParams() instanceof CoordinatorLayout.LayoutParams) {\n      CoordinatorLayout.LayoutParams layoutParams =\n          (CoordinatorLayout.LayoutParams) sheet.getLayoutParams();\n      int absoluteGravity =","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/sidesheet/SheetDialog.java#L329-L365","documentation":"SheetDialog.setSheetEdge() throws IllegalStateException when the sheet view has already been laid out. Runtime edge changes are unsupported: the sheet's behavior, delegate, and animations are bound to the initial edge, so once View.isLaidOut() is true the API refuses the change to avoid inconsistent state.","triggerScenarios":"Calling setSheetEdge(...) on a sheet dialog that is currently shown or has been shown once (the sheet passed a layout pass); e.g. toggling the edge from a menu action while the sheet is open.","commonSituations":"Persisted 'side sheet on left/right' user preference applied after the first show; reusing a dialog instance and calling setSheetEdge on subsequent shows; edge-switch UI inside the sheet itself.","solutions":["Dismiss and recreate the SheetDialog when the edge must change, calling setSheetEdge(gravity) before show() (right after construction the sheet is null — set it in onCreate after setContentView, or right after show() before layout).","Apply the edge preference at dialog construction time each session instead of mutating a live dialog.","If mid-session switching is required, drive it through SideSheetBehavior on a fresh sheet instance rather than the dialog API."],"exampleFix":"// before\nsideSheetDialog.setSheetEdge(Gravity.LEFT); // throws: sheet already laid out / shown\n\n// after\nsideSheetDialog.dismiss();\nsideSheetDialog = SideSheetDialog(context);\nsideSheetDialog.show();\nsideSheetDialog.setSheetEdge(Gravity.LEFT); // fresh sheet, not yet laid out","handlingStrategy":"validation","validationCode":"if (!sheetView.isLaidOut()) {\n  dialog.setSheetEdge(gravity);\n} else {\n  recreateDialogWithEdge(gravity);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Recreate SheetDialog instances instead of reconfiguring live ones.","Read the Javadoc contract: edge changes are init-time only, never runtime."],"tags":["android","material-components","sidesheet","dialog","lifecycle"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}