【问题标题】:VerticalScroll is not working in the Jetpack compose columnVerticalScroll 在 Jetpack 撰写列中不起作用
【发布时间】:2021-10-29 08:33:31
【问题描述】:

我在列中有一个项目列表和其他视图。我想将列设置为可滚动,但出现错误。

我的屏幕代码:

 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))

        }

这是错误:

【问题讨论】:

标签: android android-jetpack-compose


【解决方案1】:

您不会将滚动应用于作为 LazyColumn 的父级的 Column。这样做会产生您所看到的错误。 LazyColumn 已经内置了对滚动的支持。从您的列中删除verticalScroll。如果需要保持滚动位置的状态,请设置 LazyColumn 的 LazyListState 属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-25
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 2021-07-24
    • 2022-08-12
    • 2020-08-21
    • 1970-01-01
    相关资源
    最近更新 更多