首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jetpack在LazyColumn中编写LazyCloumn

Jetpack在LazyColumn中编写LazyCloumn
EN

Stack Overflow用户
提问于 2021-12-18 07:00:37
回答 1查看 4.6K关注 0票数 7

在我的主页上,我有一个懒人栏,其中一个项目是水平寻呼机。在每个水平寻呼机,有一些页面,我需要有lazyColumn在他们里面也。错误是,您不允许使用嵌套滚动相同的方向。我应该如何实现这个ui?

代码语言:javascript
复制
@Composable
fun Home() {
    LazyColumn {
        item { }
        item { }
        item { }

        item {
            TabRow(selectedTabIndex =) {

            }
        }
        item {
            HorizontalPager(count =) { page ->
                
                when {
                    page == 0 -> {
                        LazyColumn {
                            items(list) {
                                
                            }
                        }
                        
                    }
                }
            }
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2021-12-18 10:19:47

我创造了一个例子。对我来说,它就像预期的那样工作。请看一看

代码语言:javascript
复制
class ComposeActivity8 : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            ComposeTutorialTheme {
                Home()
            }
        }
    }

    @Composable
    fun VItem(text: String) {
        Text(modifier = Modifier.padding(40.dp), text = text)
        Divider(color = Color.Black)
    }

    @Composable
    fun HItem(content: @Composable BoxScope.() -> Unit) {
        Box {
            content()
            Divider(
                color = Color.Red, modifier = Modifier
                    .align(Alignment.CenterEnd)
                    .fillMaxHeight()
                    .width(1.dp)
            )
        }
    }

    @Composable
    fun CreateLazyColumn(pos: String, countItem: Int) {
        LazyColumn {
            items(count = countItem, itemContent = { index ->
                VItem("$pos.$index")
            })
        }
    }

    @Composable
    fun Home() {
        LazyColumn {
            item { VItem("Vertical item 1") }
            item { VItem("Vertical item 2") }
            item { VItem("Vertical item 3") }
            item { VItem("Vertical item 4") }
            item {
                LazyRow(modifier = Modifier.height(150.dp)) {
                    item {
                        HItem {
                            CreateLazyColumn("Horizontal item 5.1", 6)
                        }
                    }
                    item {
                        HItem {
                            CreateLazyColumn("Horizontal item 5.2", 10)
                        }
                    }
                    item {
                        HItem {
                            Text(
                                modifier = Modifier.padding(40.dp),
                                text = "Horizontal item 5.3"
                            )
                        }
                    }
                    item {
                        HItem {
                            Text(
                                modifier = Modifier.padding(40.dp),
                                text = "Horizontal item 5.4"
                            )
                        }
                    }
                    item {
                        HItem {
                            CreateLazyColumn("Horizontal 5.5", 6)
                        }
                    }
                    item {
                        HItem {
                            Text(
                                modifier = Modifier.padding(40.dp),
                                text = "Horizontal item 5.6"
                            )
                        }
                    }
                    item {
                        HItem {
                            Text(
                                modifier = Modifier.padding(40.dp),
                                text = "Horizontal item 5.7"
                            )
                        }
                    }
                    item {
                        HItem {
                            Text(
                                modifier = Modifier.padding(40.dp),
                                text = "Horizontal item 5.8"
                            )
                        }
                    }
                }
                Divider(color = Color.Black)
            }
            item { VItem("Vertical item 6") }
            item { VItem("Vertical item 7") }
            item { VItem("Vertical item 8") }
            item { VItem("Vertical item 9") }
            item { VItem("Vertical item 10") }
            item { VItem("Vertical item 11") }
            item { VItem("Vertical item 12") }
        }
    }
}

视频

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70401570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档