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>
You must have parent layout as CoordinatorLayout. You put the CoordinatorLayout where you place the container. The container must be under the CoordinatorLayout.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.