[英]How to anchor Elements to BottomSheet with JetpackCompose?
I am using BottomSheetScaffold to display a BottomSheet.我正在使用BottomSheetScaffold 来显示BottomSheet。
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = rememberBottomSheetState(
initialValue = BottomSheetValue.Collapsed
)
)
BottomSheetScaffold(
sheetContent = {
MySheet()
},
scaffoldState = bottomSheetScaffoldState) {
MyMainContent()
}
)
Now I would like to display elements above the sheet which will move along when expanding or closing the sheet.现在我想在工作表上方显示元素,这些元素在展开或关闭工作表时会移动。 eg like this:
例如像这样:
The elements are not FloatingActionButtons.这些元素不是 FloatingActionButtons。
Is there a Modifier I could use?有我可以使用的修饰符吗? Can this be achieved with the Box Layout, is there some CoordinatorLayout mode for it?
这可以通过 Box Layout 来实现,是否有一些 CoordinatorLayout 模式? Do I need to write my own layout?
我需要编写自己的布局吗?
In general: How can I achieve this with Jetpack Compose?一般而言:如何使用 Jetpack Compose 实现这一目标?
I don't know if there's something built-in in compose (in version rc01
).我不知道 compose 中是否有内置的东西(在
rc01
版本中)。 But you can achieve this behavior setting transparent color to the sheetBackgroundColor
parameter... Something like this:但是你可以实现这种行为,为
sheetBackgroundColor
参数设置透明颜色......像这样:
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = rememberBottomSheetState(
initialValue = BottomSheetValue.Collapsed
)
)
BottomSheetScaffold(
// the whole sheet will be transparent.
sheetBackgroundColor = Color.Transparent,
sheetContent = {
Column {
Text(
text = "Element",
Modifier
.align(Alignment.CenterHorizontally)
.wrapContentWidth()
.background(Color.Red)
.padding(24.dp)
)
// Your bottom sheet content
Box(
Modifier
.fillMaxWidth()
.background(Color.White)) {
// content
}
}
},
scaffoldState = bottomSheetScaffoldState
) {
// The main content
Box(
Modifier
.fillMaxSize()
.background(Color.Black)) {
}
}
Here is the result:结果如下:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.