我有自定义
Bottomsheet
布局,附有BottomSheetBehavior
。但是在初始化之后,当我将 Bottomsheet
设置为 state
时,我立即看到 EXPANDED
卷起,但是在它的内容消失之后。我不确定是什么导致了这个问题,但我根本无法弄清楚。没有什么是强制删除代码中的BottomSheet
内容。
BaseBottomSheet 类 - 设置行为的函数:
fun setBehaviour(v: ViewGroup){
App.log("BaseBottomSheet: setBehaviour")
bottomSheetBehavior = BottomSheetBehavior.from(v)
bottomSheetBehavior?.apply {
peekHeight = 0
setBottomSheetState(BottomSheetBehavior.STATE_EXPANDED)
skipCollapsed = true
isHideable = false
}
}
Activity 类初始化/附加 BottomSheet 到它的通用父级:
open fun addBottomSheet(bs: BaseBottomSheet) {
bottomSheetParent?.let {
bottomSheet = bs
//add custom content into layout
it.addView(bs.getBottomSheetLayout())
bs.setBehaviour(it)
}
}
bottomSheetParent - xml
<FrameLayout
android:id="@+id/bottomSheetContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_insetEdge="bottom"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
</FrameLayout>
FrameLayout
是CoordinatorLayout
的一部分。在这个CoordinatorLayout
里面还有其他视图(但只有上面的按钮)
bs.getBottomSheetLayout()
将返回具有独特布局(可以是任何东西)的个人
ViewGroup
的父母BottomSheet
。
我什至检查了
Layout Inspector
,内容一消失,Layout Inspector
就告诉我FrameLayout
有childCount 0
。所以后台有东西正在从该视图中删除我的附加内容。我那里没有任何removeAllViews()
电话。