kotlin 在Jetpack Compose中不添加内容填充即可防止阴影剪切

kkbh8khc  于 2023-11-21  发布在  Kotlin
关注(0)|答案(1)|浏览(147)

这个问题指出,为了在Jetpack Compose中不剪切LazyRow/LazyColumn上的阴影,你需要添加ContentPadding。然而,我想做"clipToPadding=false"的等效操作,而不添加额外的填充(填充应该是0.dp)。这可能吗?或者你必须在对象周围有某种1.dp填充?
例如:

LazyRow(
        state = listState,
        flingBehavior = flingBehavior,
        contentPadding = PaddingValues(all = 0.dp)
    )

字符串
请参见剪切左侧边缘上的阴影:
x1c 0d1x的数据

tkclm6bt

tkclm6bt1#

LazyRow(
    state = listState,
    flingBehavior = flingBehavior,
    contentPadding = PaddingValues(horizontal = 0.dp)
) {
    items(itemsList) { item ->
        Box(
            modifier = Modifier
                .padding(horizontal = 8.dp) // add small padding to each item
                .drawWithContent {
                    drawContent() // draw the content
                    drawRect(
                        color = Color.Black, // define your shadow color
                        size = Size(size.width, 16f), // adjust shadow size
                        style = Shadow(style = ShadowStyle.Cut), // set the shadow style
                        shape = RectangleShape, // use a shape
                        topLeft = Offset(x = 0f, y = size.height - 16f) // set shadow offset
                    )
                }
        ) {
            // your content
        }
    }
}

字符串

相关问题