android - 如何在 Jetpack Compose 中显示卡片外的惰性列表项目

标签 android kotlin scroll android-jetpack-compose lazylist

我在卡片中有 LazyRow,并且我希望滚动项目出现在卡片之外, 你能指导一下我吗?我该怎么做?

enter image description here

enter image description here

预先感谢您的帮助。

最佳答案

当您需要在Card上显示某些内容时,可以使用Box。您可以计算出与卡匹配所需的填充量。在这种情况下,将 Card 视为背景 View 。

val outerPadding = 20.dp
val innerPadding = 20.dp
Box {
    Card(
        backgroundColor = Color.White,
        elevation = 10.dp,
        modifier = Modifier.padding(outerPadding).aspectRatio(1f).fillMaxWidth()
    ) {

    }
    Column(
        Modifier
            .matchParentSize()
            .padding(vertical = outerPadding + innerPadding)
    ) {
        Text(
            "Your title",
            modifier = Modifier.padding(horizontal = outerPadding + innerPadding)
        )
        HorizontalPager(
            count = 10,
            contentPadding = PaddingValues(horizontal = outerPadding + innerPadding),
            itemSpacing = innerPadding / 2,
            modifier = Modifier.weight(1f)
        ) {
            Box(Modifier.fillMaxSize().background(Color.Green))
        }
        Text(
            "Your indicator",
            modifier = Modifier
                .padding(horizontal = outerPadding + innerPadding)
                .align(Alignment.CenterHorizontally)
        )
    }
}

结果:

关于android - 如何在 Jetpack Compose 中显示卡片外的惰性列表项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71796991/

相关文章:

javascript - Scrollify 滚动元素

Android Java,来自资源的位图

android - 测试运行失败 : Unable to find instrumentation info for: ComponentInfo

android - 如何在 Android 上实现 ionic io 推送通知

javascript - 在 Flash 中禁用使用箭头键滚动

c# - 如何检测鼠标滚轮方向(向前或向后)

Android 设备关机 - 想要 "ShutdownThread->shutdown()"而不是 "su reboot -p"

android - Google Places Android 显示错误 "place fields must not be empty"?

java - 在 Kotlin 项目中包含使用 Java9 或 Java10 构建的 Maven 依赖项

android - 约束布局以编程方式未使用所有分配的空间(未填充宽度)