Android BottomSheetDialogFragment未显示
我在android应用程序中实现了BottomSheetDiaogFragment 这是我的底部工作表布局(bottom_sheet.xml): 活动:Android BottomSheetDialogFragment未显示,android,kotlin,bottom-sheet,Android,Kotlin,Bottom Sheet,我在android应用程序中实现了BottomSheetDiaogFragment 这是我的底部工作表布局(bottom_sheet.xml): 活动: private val bottomSheetTaskRepeat = BottomSheetTaskRepeat() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) bottomSheetTask
private val bottomSheetTaskRepeat = BottomSheetTaskRepeat()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
bottomSheetTaskRepeat.show(supportFragmentManager, "my_bottom_sheet")
}
问题是底部的纸张没有显示出来!感谢您的帮助。这是一个迟来的答案,我为任何将面临同样问题的人写信,这是我发现的: 由于某些原因,非约束视图高度在
BottomSheetDialogFragment
中不起作用。高度类似于wrap\u content
的视图将不显示(但阴影将在那里),但当您指定其高度类似于80dp
时,它会工作
对于此问题,请将您的RadioGroup
高度更改为:
android:layout_height="200dp"
希望这是有帮助的
更新:
由于BottomSheetDailogFragment
的默认容器是FrameLayout
,并且设置为WRAP\u CONTENT
,因此可以在FragmentonStart
方法上覆盖该容器,如下所示(Kotlin):
override-fun-onStart(){
super.onStart()
val containerID=com.google.android.material.R.id.design\u bottom\u表
val底页:FrameLayout?=对话框?.findViewById(containerID)
底片?让我看看{
行为。从(它)。状态=
BottomSheetBehavior.STATE\u HALF\u已展开
bottomSheet.layoutParams.height=FrameLayout.layoutParams.MATCH\u父项
}
视图?.post{
val params=(视图?.parent作为视图)。layoutParams作为(CoordinatorLayout.layoutParams)
val behavior=params.behavior
val bottomSheetBehavior=行为为(bottomSheetBehavior)
bottomSheetBehavior.peekHeight=视图?.measuredHeight?:0
(底页?.parent as?View)?.setBackgroundColor(颜色.透明)
}
}
能否设置一个断点来检查执行是否达到bottomSheetTaskRepeat.show..
?因为我运行了你的代码,它运行得很好。最好检查底部工作表对话框片段中是否有任何dismise()
调用。也要在它被称为的地方进行检查。有时突然解雇也会这样。
private val bottomSheetTaskRepeat = BottomSheetTaskRepeat()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
bottomSheetTaskRepeat.show(supportFragmentManager, "my_bottom_sheet")
}
android:layout_height="200dp"
override fun onStart() {
super.onStart()
val containerID = com.google.android.material.R.id.design_bottom_sheet
val bottomSheet: FrameLayout? = dialog?.findViewById(containerID)
bottomSheet?.let {
BottomSheetBehavior.from<FrameLayout?>(it).state =
BottomSheetBehavior.STATE_HALF_EXPANDED
bottomSheet.layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT
}
view?.post {
val params = (view?.parent as View).layoutParams as (CoordinatorLayout.LayoutParams)
val behavior = params.behavior
val bottomSheetBehavior = behavior as (BottomSheetBehavior)
bottomSheetBehavior.peekHeight = view?.measuredHeight ?: 0
(bottomSheet?.parent as? View)?.setBackgroundColor(Color.TRANSPARENT)
}
}