kotlin 长方体的阴影未剪裁到形状

nwnhqdif  于 2023-03-30  发布在  Kotlin
关注(0)|答案(1)|浏览(141)

我有一个有形状的盒子,但是立面阴影看起来并没有剪裁到它,因为它看起来仍然是矩形的。为什么会发生这种情况?

Box(
                           modifier = Modifier
                               .scale(scale)
                               .alpha(alpha)
                               .blur(1.dp)
                               .shadow(
                                   elevation = 10.dp,
                                   shape = RoundedCornerShape(25.dp)
                               )
                       ) {
                           Image(
                              
                               painter = painterResource(id = R.drawable.placeholder),
                               contentScale = ContentScale.Crop,
                               modifier = Modifier
                                   .size(width = 100.dp, height = 200.dp)
                                   .clip(RoundedCornerShape(25.dp)),
                               contentDescription = null
                           )
                       }
mitkmikd

mitkmikd1#

立面阴影未剪裁到长方体圆角的问题可能是由于在应用阴影后剪裁长方体的事实。
要解决此问题,请尝试在剪辑后应用阴影,如下所示:

Box(
    modifier = Modifier
        .scale(scale)
        .alpha(alpha)
        .blur(1.dp)
        .clip(RoundedCornerShape(25.dp))
        .shadow(
            elevation = 10.dp,
            shape = RoundedCornerShape(25.dp)
        )
) {
    Image(
        painter = painterResource(id = R.drawable.placeholder),
        contentScale = ContentScale.Crop,
        modifier = Modifier
            .size(width = 100.dp, height = 200.dp),
        contentDescription = null
    )
}

通过首先裁剪长方体,然后应用具有相同RoundedCornerShape的阴影,现在应该将立面裁剪到长方体的圆角,从而创建所需的效果。

相关问题