根据https://google.github.io/accompanist/insets/,我们可以使用嵌套滚动连接来控制滚动时的键盘外观。
sample code 具有 LazyColumn 的现代实现:
LazyColumn(
reverseLayout = true,
modifier = Modifier
.weight(1f)
.nestedScroll(connection = rememberImeNestedScrollConnection())
) {
items(listItems) { imageUrl -> ListItem(imageUrl, Modifier.fillMaxWidth())
}
}
文档中有 ScrollableColumn
的示例,它在 beta06 中不再存在:
// Here we're using ScrollableColumn, but it also works with LazyColumn, etc.
ScrollableColumn(
// We use the nestedScroll modifier, passing in the
// the connection from rememberImeNestedScrollConnection()
modifier = Modifier.nestedScroll(
connection = rememberImeNestedScrollConnection()
)
) {
// list content
}
Modifier.verticalScroll()
的等价物是什么?我试过将它与 nestedScroll()
结合使用没有效果。
val imeNestedScrollConnection = rememberImeNestedScrollConnection()
Column(
modifier = modifier
.fillMaxHeight()
.fillMaxWidth()
.verticalScroll(scrollState)
.nestedScroll(imeNestedScrollConnection)
.padding(horizontal = spacing, vertical = 8.dp),
horizontalAlignment = Alignment.CenterHorizontally
) { ... }
我尝试过的其他事情