Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android BottomSheetDialogFragment未显示_Android_Kotlin_Bottom Sheet - Fatal编程技术网

Android BottomSheetDialogFragment未显示

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

我在android应用程序中实现了BottomSheetDiaogFragment

这是我的底部工作表布局(bottom_sheet.xml):

活动:

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
,因此可以在Fragment
onStart
方法上覆盖该容器,如下所示(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)

    }
}