Jetpack compose 中看不到圆角

问题描述 投票:0回答:1

我正在尝试将其作为第一次喷气背包练习

其实这是代码,唯一缺少的是圆角,我尝试了一下,它确实剪辑了内容,但不可见。

@Preview
@Composable()
fun Horizontal_card (){
Row(
    Modifier
        .size(width = 352.dp, height = 80.dp)
        .background(MaterialTheme.colors.background)
        .clip(RoundedCornerShape(10.dp)),
    verticalAlignment = Alignment.CenterVertically) {
    Spacer(Modifier.width(16.dp))
    Cardcontent ()
}

}

这是组件的预览:

android kotlin android-jetpack-compose android-jetpack
1个回答
9
投票

修饰符的顺序很重要。此时您设置背景

fun Modifier.background(
    color: Color,
    shape: Shape = RectangleShape
) = this.then(
    Background(
        color = color,
        shape = shape,
        inspectorInfo = debugInspectorInfo {
            name = "background"
            value = color
            properties["color"] = color
            properties["shape"] = shape
        }
    )
)

默认使用

RectangleShape

您应该致电

Modifier
    .size(width = 352.dp, height = 80.dp)
    .background(MaterialTheme.colors.background, RoundedCornerShape(10.dp))

Modifier
 .size(width = 352.dp, height = 80.dp)
 .clip(RoundedCornerShape(10.dp))
 .background(MaterialTheme.colors.background)
© www.soinside.com 2019 - 2024. All rights reserved.