[英]fillMaxSize modifier not working when combined with VerticalScroll in Jetpack Compose
[英]VerticalScroll is not working in the Jetpack compose column
我在列中有一个项目列表和其他视图。 我想将可滚动设置为列,但出现错误。
我的屏幕代码:
val context = LocalContext.current
Box(
modifier = modifier
.fillMaxSize()
) {
val state = viewModel.state.value
val scrollState = rememberScrollState()
Column(modifier = modifier.fillMaxSize().verticalScroll(scrollState)) {
Spacer(modifier = Modifier.size(24.dp))
AccountNameSection(modifier = modifier)
Spacer(modifier = Modifier.size(24.dp))
if (!state.items.isNullOrEmpty()) {
Box(modifier = modifier.fillMaxSize()) {
LazyColumn(modifier = modifier.fillMaxSize()) {
items(state.items) { item ->
ProfileListItems(item = item, onItemClick = {
})
}
}
}
}
Text(text = context.getAppVersionName())
}
if (state.error.isNotBlank())
SimpleSnackbar(
text = state.error,
modifier = modifier.align(Alignment.BottomCenter)
)
if (state.isLoading)
Loading(modifier = modifier.align(Alignment.BottomCenter))
}
这是错误:
您不会将滚动应用于作为 LazyColumn 的父级的 Column。 这样做会产生您所看到的错误。 LazyColumn 已经内置了对滚动的支持。 从您的列中删除verticalScroll。 如果需要保持滚动位置的状态,设置 LazyColumn 的 LazyListState 属性。
如果不根据 android 文档设置特定高度,则不能将lazyColumn 作为列的子级。
用作示例:
LazyColumn(modifier = modifier.width(200.dp)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.