{"record":{"id":"64867c2f6e68692d","repo":"material-components/material-components-android","slug":"this-behavior-cannot-be-attached-to-a-gone-view-s","errorCode":null,"errorMessage":"This behavior cannot be attached to a GONE view. Set the view to INVISIBLE instead.","messagePattern":"This behavior cannot be attached to a GONE view\\. Set the view to INVISIBLE instead\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/transformation/FabTransformationBehavior.java","lineNumber":96,"sourceCode":"  private final int[] tmpArray = new int[2];\n\n  // The original translation of the dependency. Used to translate the dependency back to its\n  // original position.\n  private float dependencyOriginalTranslationX;\n  private float dependencyOriginalTranslationY;\n\n  public FabTransformationBehavior() {}\n\n  public FabTransformationBehavior(Context context, AttributeSet attrs) {\n    super(context, attrs);\n  }\n\n  @Override\n  @CallSuper\n  public boolean layoutDependsOn(\n      @NonNull CoordinatorLayout parent, @NonNull View child, @NonNull View dependency) {\n    if (child.getVisibility() == View.GONE) {\n      throw new IllegalStateException(\n          \"This behavior cannot be attached to a GONE view. Set the view to INVISIBLE instead.\");\n    }\n\n    if (dependency instanceof FloatingActionButton) {\n      int expandedComponentIdHint =\n          ((FloatingActionButton) dependency).getExpandedComponentIdHint();\n      return expandedComponentIdHint == 0 || expandedComponentIdHint == child.getId();\n    }\n    return false;\n  }\n\n  @Override\n  @CallSuper\n  public void onAttachedToLayoutParams(@NonNull CoordinatorLayout.LayoutParams lp) {\n    if (lp.dodgeInsetEdges == Gravity.NO_GRAVITY) {\n      // If the developer hasn't set dodgeInsetEdges, lets set it to BOTTOM so that\n      // we dodge any Snackbars, matching FAB's behavior.\n      lp.dodgeInsetEdges = Gravity.BOTTOM;","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/transformation/FabTransformationBehavior.java#L78-L114","documentation":"FabTransformationBehavior.layoutDependsOn (FabTransformationBehavior.java:96) throws IllegalStateException when the child view carrying this behavior is View.GONE. A GONE child is skipped by CoordinatorLayout's dependency/measure passes, so the FAB-to-content transformation machinery would never run correctly; INVISIBLE keeps the view laid out and merely not drawn, which is what the behavior requires. This is a fail-fast contract check, not a recoverable runtime condition.","triggerScenarios":"Declaring the expanded content view with android:visibility=\"gone\" while attaching FabTransformationBehavior via app:layout_behavior; calling expandedView.setVisibility(View.GONE) before the first layout pass or while the behavior is attached.","commonSituations":"Wanting the transformed sheet hidden initially; the natural instinct is GONE, but this behavior requires INVISIBLE (optionally with 0 alpha/elevation so it is not visible to the user).","solutions":["Set android:visibility=\"invisible\" on the child instead of gone.","If you need the view visually hidden initially, keep INVISIBLE and additionally set android:alpha=\"0\" or call setAlpha(0f).","If GONE is a hard requirement, remove the layout_behavior before hiding and re-attach after showing."],"exampleFix":"<!-- before -->\n<View android:id=\"+id/sheet\"\n    android:visibility=\"gone\"\n    app:layout_behavior=\"...FabTransformationBehavior\" ... />\n\n<!-- after -->\n<View android:id=\"+id/sheet\"\n    android:visibility=\"invisible\"\n    android:alpha=\"0\"\n    app:layout_behavior=\"...FabTransformationBehavior\" ... />","handlingStrategy":"validation","validationCode":"// before hiding a view that carries a FabTransformationBehavior:\nif (view.getVisibility() == View.GONE && hasFabTransformationBehavior(view)) {\n  view.setVisibility(View.INVISIBLE);\n  view.setAlpha(0f);\n} else {\n  view.setVisibility(View.GONE);\n}","typeGuard":"boolean hasFabTransformationBehavior(View v) {\n  ViewGroup.LayoutParams p = v.getLayoutParams();\n  return p instanceof CoordinatorLayout.LayoutParams\n      && ((CoordinatorLayout.LayoutParams) p).getBehavior() instanceof FabTransformationBehavior;\n}","tryCatchPattern":null,"preventionTips":["Use INVISIBLE (+ alpha 0 if needed) for views attached to FabTransformationBehavior, never GONE.","Review visibility changes in shared view-model/UI code so nothing flips these views to GONE.","Add a lint/custom check or unit test asserting transformation views are never GONE at layout time."],"tags":["android","material-components","fab-transformation","view-visibility","coordinatorlayout"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}