[英]VerticalScroll is not working in the Jetpack compose column
I have a list of items and other views in the column.我在列中有一个项目列表和其他视图。 I want to set scrollable to the column but I get an error.我想将可滚动设置为列,但出现错误。
My screen code:我的屏幕代码:
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))
}
This is the error:这是错误:
You don't apply scrolling to a Column that is a parent to a LazyColumn.您不会将滚动应用于作为 LazyColumn 的父级的 Column。 Doing so will generate the error that you are seeing.这样做会产生您所看到的错误。 A LazyColumn already has built-in support for scrolling. LazyColumn 已经内置了对滚动的支持。 Remove verticalScroll from your Column.从您的列中删除verticalScroll。 If you need to maintain the state of the scroll position, set the LazyListState property of the LazyColumn.如果需要保持滚动位置的状态,设置 LazyColumn 的 LazyListState 属性。
You cannot put lazyColumn as child of column without setting specific height according to android documentation.如果不根据 android 文档设置特定高度,则不能将lazyColumn 作为列的子级。
Use as example:用作示例:
LazyColumn(modifier = modifier.width(200.dp)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.