Home > Software design >  BottomSheet : The view is not a child of CoordinatorLayout
BottomSheet : The view is not a child of CoordinatorLayout

Time:01-15

I've checked other posts having this problem and they said use <merge> instead of <include> but when i use <merge> it shows red in my fragment.xml file, there is no such tag. How can i solve this error?

In my fragment.xml:

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include layout="@layout/product_variation_bottom_sheet" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

In my Fragment.kt:

var view = inflater.inflate(R.layout.bottom_sheet, container, false)
bottomSheetBehavior = BottomSheetBehavior.from(view.findViewById(R.id.bottomSheet))

In my bottom_sheet.xml:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@ id/productVariationBottomSheet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/bottom_sheet_behavior"
    app:behavior_peekHeight="0sp"
    app:behavior_hideable="true"
    android:background="#00000000"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    //some other views
</LinearLayout>

CodePudding user response:

You must have parent layout as CoordinatorLayout. You put the CoordinatorLayout where you place the container. The container must be under the CoordinatorLayout.

CodePudding user response:

Couldn't find any solution to solve it, so i stopped using <include> and just put all the BottomSheet's layout code into my fragment.xml altogether. Then access the BottomSheet layout directly using viewBinding. This way, it works. Any other solution that works, feel free to share your solution.

  •  Tags:  
  • Related