gpt4 book ai didi

kotlin - Jetpack 组成 : scrolling in dialog gives strange effects

转载 作者:行者123 更新时间:2023-12-05 03:36:15 26 4
gpt4 key购买 nike

我正在尝试创建一个对话框,您可以在其中选择一个数字。我使用 Accompanist 的 FlowRow。但是滚动时会产生奇怪的结果。我想我在这里遗漏了一些东西。

代码:

@Composable
fun AlertDialogErrorTest() {
var showDlg by remember { mutableStateOf(false)}
val scrollState = rememberScrollState()
if (showDlg) {
AlertDialog(
onDismissRequest = { showDlg = false },
title = { Text(text = "Pick something from the list") },
text = {
FlowRow(modifier = Modifier.verticalScroll(scrollState)) {
for (i in 1..100) {
Box (modifier = Modifier.size(48.dp).padding(8.dp).background(Color.LightGray), contentAlignment = Alignment.Center) {
Text (i.toString())
}
}
}
},
confirmButton = {
TextButton(onClick = { showDlg = false }) {
Text("Done")
}
},
dismissButton = {
TextButton(onClick = { showDlg = false }) {
Text("Cancel")
}
}
)
}

Button(onClick = {showDlg = true}) {
Text("Show dialog")
}
}

滚动时的结果:

最佳答案

这是因为AlertDialog 目前不支持滚动内容。如果你认为这是一个错误,你可以report it在 Compose 问题跟踪器中。

与此同时,您可以使用普通的 Dialog ,位于 AlertDialog 下。

Dialog(
onDismissRequest = { showDlg = false },
content = {
Column(Modifier.background(Color.White)) {
Text(
text = "Pick something from the list",
style = MaterialTheme.typography.subtitle1,
modifier = Modifier.align(Alignment.CenterHorizontally)
)
FlowRow(
modifier = Modifier
.verticalScroll(scrollState)
.weight(1f)
) {
for (i in 1..100) {
Box(
modifier = Modifier
.size(48.dp)
.padding(8.dp)
.background(Color.LightGray),
contentAlignment = Alignment.Center
) {
Text(i.toString())
}
}
}
FlowRow(
mainAxisSpacing = 8.dp,
crossAxisSpacing = 12.dp,
modifier = Modifier
.align(Alignment.End)
.padding(horizontal = 8.dp, vertical = 2.dp)
) {
TextButton(onClick = { showDlg = false }) {
Text("Cancel")
}
TextButton(onClick = { showDlg = false }) {
Text("Done")
}
}
}
},
)

结果:

关于kotlin - Jetpack 组成 : scrolling in dialog gives strange effects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69683622/

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