gpt4 book ai didi

android - 动态设置底板的最大展开高度

转载 作者:行者123 更新时间:2023-12-02 21:19:08 26 4
gpt4 key购买 nike

How to set maximum expanded height in android support design bottom sheet?

这个问题是上述问题的扩展,我想设置工作表的最大展开高度,但根据屏幕尺寸动态设置。

我尝试为实现底部行为的 View 设置新的布局参数,但它没有任何好处。

最佳答案

请使用这个并冷静:)

  1. const val BOTTOMSHEET_HEIGHT_TO_SCREEN_HEIGHT_RATIO = 0.80//根据您的要求更改
  2. 覆盖bottomsheetFragment中的onCreateDialog()
<小时/>
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
dialog.setOnShowListener {
dialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
?.apply {
val maxDesiredHeight =
(resources.displayMetrics.heightPixels * BOTTOMSHEET_HEIGHT_TO_SCREEN_HEIGHT_RATIO).toInt()
if (this.height > maxDesiredHeight) {
val bottomSheetLayoutParams = this.layoutParams
bottomSheetLayoutParams.height = maxDesiredHeight
this.layoutParams = bottomSheetLayoutParams
}
BottomSheetBehavior.from(this)?.apply {
this.state = BottomSheetBehavior.STATE_EXPANDED
this.skipCollapsed = true
}
}
}
return dialog
}

关于android - 动态设置底板的最大展开高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49333896/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com