gpt4 book ai didi

android - Jetpack Compose 列中的 fillViewPort 行为

转载 作者:行者123 更新时间:2023-12-03 22:58:48 40 4
gpt4 key购买 nike

有没有类似 ScrollView 的东西fillViewPort在 Jetpack 中撰写 Column ?
看这个例子:

@Composable
fun FillViewPortIssue() {
Column(
Modifier
.fillMaxSize()
.padding(16.dp)
) {
for (i in 0..5) {
Box(
modifier = Modifier
.padding(vertical = 8.dp)
.background(Color.Red)
.fillMaxWidth()
.height(72.dp)
)
}
Spacer(modifier = Modifier.weight(1f))
Button(
modifier = Modifier.fillMaxWidth(),
onClick = { /*TODO*/ }
) {
Text("Ok")
}
}
}
这是结果:
enter image description here
当设备处于横向时,内容被裁剪,因为没有滚动。
如果我添加 verticalScroll修饰符做 Column ...
    ...
Column(
Modifier
.verticalScroll(rememberScrollState()) // <<-- this
.fillMaxSize()
.padding(16.dp)
) {
...
...滚动问题已解决,但按钮向上,就像这样。
enter image description here
在传统的工具包中,我们可以使用 ScrollView 来解决这个问题。 + fillViewPort属性(property)。有没有相当于 Compose 的东西?

最佳答案

只需更改起作用的修饰符的顺序...
感谢 Abhishek Dewan(来自 Kotlin Slack channel )!

Column(
Modifier
.fillMaxSize() // first, set the max size
.verticalScroll(rememberScrollState()) // then set the scroll
) {

关于android - Jetpack Compose 列中的 fillViewPort 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67929861/

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