{"record":{"id":"59d4aa05d3a65ccb","repo":"material-components/material-components-android","slug":"the-view-is-not-a-child-of-coordinatorlayout","errorCode":null,"errorMessage":"The view is not a child of CoordinatorLayout","messagePattern":"The view is not a child of CoordinatorLayout","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/behavior/HideViewOnScrollBehavior.java","lineNumber":507,"sourceCode":"   * Returns whether or not this behavior is disabled if touch exploration is enabled.\n   */\n  public boolean isDisabledOnTouchExploration() {\n    return disableOnTouchExploration;\n  }\n\n  /**\n   * A utility function to get the {@link HideViewOnScrollBehavior} associated with the {@code\n   * view}.\n   *\n   * @param view The {@link View} with {@link HideViewOnScrollBehavior}.\n   * @return The {@link HideViewOnScrollBehavior} associated with the {@code view}.\n   */\n  @NonNull\n  @SuppressWarnings(\"unchecked\")\n  public static <V extends View> HideViewOnScrollBehavior<V> from(@NonNull V view) {\n    ViewGroup.LayoutParams params = view.getLayoutParams();\n    if (!(params instanceof LayoutParams)) {\n      throw new IllegalArgumentException(\"The view is not a child of CoordinatorLayout\");\n    }\n    CoordinatorLayout.Behavior<?> behavior = ((LayoutParams) params).getBehavior();\n    if (!(behavior instanceof HideViewOnScrollBehavior)) {\n      throw new IllegalArgumentException(\n          \"The view is not associated with HideViewOnScrollBehavior\");\n    }\n    return (HideViewOnScrollBehavior<V>) behavior;\n  }\n}\n","sourceCodeStart":489,"sourceCodeEnd":517,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/behavior/HideViewOnScrollBehavior.java#L489-L517","documentation":"HideViewOnScrollBehavior.from(View) retrieves the behavior by reading view.getLayoutParams() and casting to CoordinatorLayout.LayoutParams. If the view's layout params are not CoordinatorLayout.LayoutParams, the view is not a direct child of a CoordinatorLayout and the lookup is invalid, so IllegalArgumentException is thrown.","triggerScenarios":"Calling HideViewOnScrollBehavior.from(view) on a view whose parent is not a CoordinatorLayout — e.g. a view inside a FrameLayout, ConstraintLayout, or a view not yet attached (default ViewGroup.LayoutParams).","commonSituations":"Calling from() in onCreate() before the view is inflated/attached so its LayoutParams are still the generic default; refactoring layouts so the FAB or toolbar is no longer a direct CoordinatorLayout child; calling from() on a view from a different fragment's hierarchy.","solutions":["Ensure the view is a direct child of a CoordinatorLayout with app:layout_behavior set on it.","Call from() after layout inflation/attachment (e.g. after setContentView or in onViewCreated), not before.","If the view must live in another container, move it under the CoordinatorLayout or restructure so the behavior applies to a direct child."],"exampleFix":"<!-- before -->\n<FrameLayout ...>\n  <androidx.appcompat.widget.Toolbar ... />\n</FrameLayout>\n\n<!-- after -->\n<androidx.coordinatorlayout.widget.CoordinatorLayout ...>\n  <androidx.appcompat.widget.Toolbar\n      app:layout_behavior=\"com.google.android.material.beh.HideViewOnScrollBehavior\"\n      ... />\n</androidx.coordinatorlayout.widget.CoordinatorLayout>","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"private static boolean isCoordinatorChild(View v) {\n  return v.getLayoutParams() instanceof CoordinatorLayout.LayoutParams;\n}","tryCatchPattern":null,"preventionTips":["Call from() only after inflation/attachment.","Keep behavior-bearing views as direct children of CoordinatorLayout."],"tags":["behavior","coordinatorlayout","illegal-argument","view-hierarchy"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}