You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在BottomSheetScaffold中随BottomSheet动态调整内容高度

BottomSheetScaffold内容区域高度随底部面板动态调整的优化需求

我希望在BottomSheetScaffold中,让内容区域的高度随BottomSheet的展开/收起动态变化——底部面板收起时内容高度较高,展开时内容高度较低。

目前我的实现代码如下:

val bottomSheetState = rememberBottomSheetState(initialValue =BottomSheetValue.Expanded )

val bottomSheetScaffoldState= rememberBottomSheetScaffoldState(
        bottomSheetState = bottomSheetState)

val heightPixels= LocalContext.current.resources.displayMetrics.heightPixels

BottomSheetScaffold(
modifier = Modifier.fillMaxSize()
sheetPeekHeight = 68.dp,
scaffoldState = bottomSheetScaffoldState,
sheetContent = {
    /*
    sheet content
     */
}) {
    Box(modifier = Modifier
        .fillMaxWidth()
        .fillMaxHeight(((bottomSheetState.offset.value)
                / (heightPixels)).let { if (it == 0f) 1f else it })
    ) {
        /*
        content
         */
    }
}

但这个实现存在两个问题:

  • 依赖系统像素高度,适配不同设备时容易出现偏差
  • 每次BottomSheet高度变化时,承载内容的Box都会发生重组

内容的提问来源于stack exchange,提问作者Eray Agdoğan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 11:05:31