BottomSheetBehavior is not a child of CoordinatorLayout

the view is not associated with bottomsheetbehavior android
bottomsheetbehavior androidx
bottomsheetbehavior onintercepttouchevent
bottomsheetbehavior state dragging
bottomsheetbehavior state_expanded
bottom sheet not showing
android bottom sheet disable drag
bottomsheetbehavior sethideable

this is my XML layout with name songlist :

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/viewA"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.6"
            android:background="@android:color/holo_purple"
            android:orientation="horizontal"/>

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/bottom_sheet"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/holo_blue_bright"
            app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
            >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <ListView
                    android:id="@+id/list"
                    android:layout_width="match_parent"
                    android:layout_height="308dp"
                    />
            </LinearLayout>

        </android.support.v4.widget.NestedScrollView>
    </LinearLayout>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@drawable/personlog"
        app:layout_anchor="@id/viewA"
        app:layout_anchorGravity="bottom|center"/>

</android.support.design.widget.CoordinatorLayout>

and this is my fragment which contain this layout :

public class SongList extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.songlist,container,false);

        textView=(TextView)view.findViewById(R.id.txt);

        View bottomSheet = view.findViewById(R.id.bottom_sheet);
        BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
        bottomSheetBehavior.setPeekHeight(200);
return view;}
}

but when lunch the app give me this error :

java.lang.IllegalArgumentException: The view is not a child of CoordinatorLayout

from this line :

  BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);

how can fix this ? seems all things work fine but give that error ... if any one can please help

The BottomSheetBehavior is

An interaction behavior plugin for a child view of CoordinatorLayout to make it work as a bottom sheet.

At the moment you bottom sheet NestedScrollView is a child of LinearLayout. So just drop the outer-most LinearLayout all completely.

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/viewA"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.6"
        android:background="@android:color/holo_purple"
        android:orientation="horizontal"/>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_blue_bright"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ListView
                android:id="@+id/list"
                android:layout_width="match_parent"
                android:layout_height="308dp" />
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@drawable/personlog"
        app:layout_anchor="@id/viewA"
        app:layout_anchorGravity="bottom|center" />
</android.support.design.widget.CoordinatorLayout>

But now you have some more issues with the bottom sheet you're trying to implement. Firstly you should not use wrap_content with a scroll view. Secondly you should not use a list view inside a scroll view, since it's implementing its own scrolling. You might be able to simplify this by only using the list view as a bottom sheet.

BottomSheetBehavior is not a child of CoordinatorLayout, this is my XML layout with name songlist : <android.support.design.widget.​CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"​  </LinearLayout> </android.support.design.widget.CoordinatorLayout> All that I have done is to put the id that you will call later as your bottom sheet in the root element (Which by the way could be a ConstraintLayout if you want), as you can notice, the parent of this root element will be automatically a CoodinatorLayout.

Note, if you don't use a CoordinatorLayout and instead use the BottomSheetDialogFragment (which makes one for you), I noticed that you cannot navigate to that dialog fragment with Fragment directions using the current version of the Nav component library (2.1.0-alpha05) and must instantiate it as a new fragment dialog otherwise you get this error, i.e. instead of using this:

navController().navigate(MerchantHistoryFragmentDirections.showDateSelection())

You must use this:

fragmentManager?.let {
            val dateSelection = DateSelectionFragment.newInstance()
            dateSelection.setTargetFragment(this, RC_DATE_SELECTION)
            dateSelection.show(it)
        }

It's a kind of obtuse error so hopefully this helps someone.

android.support.design.widget.CoordinatorLayout$LayoutParams , CoordinatorLayout$LayoutParams (Showing top 20 results out of 522) null && behavior instanceof BottomSheetBehavior) { ((BottomSheetBehavior) behavior). new IllegalArgumentException("The view is not a child of CoordinatorLayout");​  I am not able to catch the events when the conditions are met, and not catch them in other cases. In the image below you can see what happens with a standard CoordinatorLayout: The sheet is dismissed if you scroll down on the appbar, but not if you scroll down on the nested content.

If you are using data binding and including the layout to the fragment you have to do like following

val sheetBehavior = BottomSheetBehavior.from(binding.layoutBottomSheet.root)

BottomSheetBehavior is not a child of CoordinatorLayout, I tried to extend the default bottomSheetBehavior with no success, so I just copy pasted all public boolean onLayoutChild(CoordinatorLayout parent, V child,  An interaction behavior plugin for a child view of CoordinatorLayout to make it work as a bottom sheet.. To send useful accessibility events, set a title on bottom sheets that are windows or are window-like.

In my case instead of

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

I used <android.support.constraint.ConstraintLayout (in a fragment or activity that contains a layout and a BottomSheet).

Bottom Sheets, The view is not a child of CoordinatorLayout. bottom_sheet.xml. activity_main.xml​. MainActivity.java package com.app; import android.os.Bundle; import  BottomSheetBehavior like Google maps. The complete file for backdrop image with parallax effect. Now for the end: The Custom BottomSheet Behavior To achieve the 3 steps, first you need to understand that default BottomSheetBehavior has 5 states: STATE_DRAGGING, STATE_SETTLING, STATE_EXPANDED, STATE_COLLAPSED, STATE_HIDDEN and for the Google Maps behavior you need to add a middle state between

why BottomSheetBehavior in androidx error The view is not a child , BottomSheetBehavior is applied to a child of CoordinatorLayout to make that child a persistent bottom STATE_HIDDEN : The bottom sheet is no longer visible. A BottomSheetBehavior is an interaction behavior plugin for a child view of CoordinatorLayout to make it work as a bottom sheet.

Bottom Sheets, In order to implement bottom sheet behavior in your app, the view you want to show as bottom sheet needs to be a direct child of coordinator layout. There are two In a collapsed state, bottom sheet is not visible to users. 2. FAB follows Widget. Unlike the previous example, this time the CoordinatorLayout is not the root layout. Rather, the root layout is a RelativeLayout, and the CoordinatorLayout is it’s only child.

How to add a Bottom Sheet to an Android App, you may not use this file except in compliance with the License. An interaction behavior plugin for a child view of {@link CoordinatorLayout} to make it work as. The new view must be direct child of CoordinatorLayout like the bottom sheet view. <android.support.design.widget.CoordinatorLayout sheet behavior BottomSheetBehavior bottomSheetBehavior

Comments
  • so how can made this layout with true way ? if u have some solution please answer
  • i add NestedScrollView inside CoordinatorLayout but still same problem
  • can understand your point . if you want help me please answer my question not comment then tell me where code must be change to what or some thing like that . tnx
  • There is also a linearlayout containing a single listview.