Tan*_*y C 7 android bottom-sheet
我在显示按钮时遇到一些麻烦BottomSheetDialogFragment。无论它是展开还是折叠,我都希望它粘在我底部的底部。
见下图:

(我用素描来创建)
有技巧或窍门吗?
以防万一,如果您知道如何在上增加最高利润bottomsheetdialog,我也想知道这一点;)
我解决这个问题的方法如下:
示例代码如下:
val bottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
bottomSheetDialog.setOnShowListener {
val dialog = it as BottomSheetDialog
dialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet) as FrameLayout
val containerLayout: FrameLayout =
dialog.findViewById<FrameLayout>(com.google.android.material.R.id.container) as FrameLayout
val button = binding.submitButton
val parent = button.parent as ViewGroup
parent.removeView(button)
containerLayout.addView(button, containerLayout.childCount)
}
return bottomSheetDialog
Run Code Online (Sandbox Code Playgroud)
这样,您的底部工作表将正常响应触摸,并且按钮将保留在父级工作表上的位置。
如果您有任何疑问,请随时询问。
编辑
不要忘记定义布局参数/将按钮定位在 R.id.container 的底部