其实这是代码,唯一缺少的是圆角,我尝试了一下,它确实剪辑了内容,但不可见。
@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 ()
}
}
修饰符的顺序很重要。此时您设置背景
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)