material-components/material-components-android · error · IllegalStateException
This behavior cannot be attached to a GONE view. Set the vie
Error message
This behavior cannot be attached to a GONE view. Set the view to INVISIBLE instead.
What it means
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.
Source
Thrown at lib/java/com/google/android/material/transformation/FabTransformationBehavior.java:96
private final int[] tmpArray = new int[2];
// The original translation of the dependency. Used to translate the dependency back to its
// original position.
private float dependencyOriginalTranslationX;
private float dependencyOriginalTranslationY;
public FabTransformationBehavior() {}
public FabTransformationBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
@CallSuper
public boolean layoutDependsOn(
@NonNull CoordinatorLayout parent, @NonNull View child, @NonNull View dependency) {
if (child.getVisibility() == View.GONE) {
throw new IllegalStateException(
"This behavior cannot be attached to a GONE view. Set the view to INVISIBLE instead.");
}
if (dependency instanceof FloatingActionButton) {
int expandedComponentIdHint =
((FloatingActionButton) dependency).getExpandedComponentIdHint();
return expandedComponentIdHint == 0 || expandedComponentIdHint == child.getId();
}
return false;
}
@Override
@CallSuper
public void onAttachedToLayoutParams(@NonNull CoordinatorLayout.LayoutParams lp) {
if (lp.dodgeInsetEdges == Gravity.NO_GRAVITY) {
// If the developer hasn't set dodgeInsetEdges, lets set it to BOTTOM so that
// we dodge any Snackbars, matching FAB's behavior.
lp.dodgeInsetEdges = Gravity.BOTTOM;View on GitHub (pinned to ac7e18efee)
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.
Example fix
<!-- before -->
<View android:id="+id/sheet"
android:visibility="gone"
app:layout_behavior="...FabTransformationBehavior" ... />
<!-- after -->
<View android:id="+id/sheet"
android:visibility="invisible"
android:alpha="0"
app:layout_behavior="...FabTransformationBehavior" ... /> Defensive patterns
Strategy: validation
Validate before calling
// before hiding a view that carries a FabTransformationBehavior:
if (view.getVisibility() == View.GONE && hasFabTransformationBehavior(view)) {
view.setVisibility(View.INVISIBLE);
view.setAlpha(0f);
} else {
view.setVisibility(View.GONE);
} Type guard
boolean hasFabTransformationBehavior(View v) {
ViewGroup.LayoutParams p = v.getLayoutParams();
return p instanceof CoordinatorLayout.LayoutParams
&& ((CoordinatorLayout.LayoutParams) p).getBehavior() instanceof FabTransformationBehavior;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- The view is not a child of CoordinatorLayout
- The view is not associated with SideSheetBehavior
- The view is not a child of CoordinatorLayout
- The view is not associated with ExpandableBehavior
- secondaryIconGravity cannot have the same alignment as iconG
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/64867c2f6e68692d.
Report an issue: GitHub.