防止阴影剪切,无需在 Jetpack Compose 中添加内容填充

sep*_*e01 9 android kotlin android-jetpack-compose

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

前任:

LazyRow(
        state = listState,
        flingBehavior = flingBehavior,
        contentPadding = PaddingValues(all = 0.dp)
    )
Run Code Online (Sandbox Code Playgroud)

查看左侧边缘的剪切阴影:

小智 0


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
        }
    }
}
Run Code Online (Sandbox Code Playgroud)