Kotlin Compose forEach 中的负间距

Her*_*. F 4 android kotlin android-jetpack-compose

我尝试在某些圆圈上设置负间距,但我没有运气:

.padding(horizontal = (-5).dp)

.offset(x = (-5).dp)

我不太确定如何实现这一点,我正在努力实现这一目标:

在此输入图像描述

正如您所看到的,图像确实包含叠加层,但图像位于彼此后面。

Kotlin Compose 有什么办法可以实现这一点吗?

Thr*_*ian 8

您可以通过用盒子包裹第二个图像来做到这一点。设置背景和偏移。

@Composable
private fun ImageSample() {

    Row(
        modifier = Modifier
            .wrapContentHeight()
            .padding(20.dp), verticalAlignment = Alignment.CenterVertically
    ) {
        Image(
            modifier = Modifier
                .size(100.dp)
                .clip(CircleShape),
            painter = painterResource(id = R.drawable.landscape1),
            contentDescription = null,
            contentScale = ContentScale.FillBounds
        )

        Box(
            modifier = Modifier
                .offset((-20).dp)
                .background(Color.White, CircleShape)
                .padding(10.dp)
        ) {
            Image(
                modifier = Modifier
                    .size(100.dp)
                    .clip(CircleShape),
                painter = painterResource(id = R.drawable.landscape2),
                contentDescription = null,
                contentScale = ContentScale.FillBounds
            )
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述