我在jetpack compose中创建了简单的卡片,在这里我设置了海拔,但它显示类型不匹配。
Card(
shape = RoundedCornerShape(20.dp),elevation = 10.dp
) {
Box(modifier = Modifier.height(200.dp)) {
Image(painter = painter, contentDescription = contentDescription,
contentScale = ContentScale.Crop)
}
}
您正在使用 M3 (
androidx.compose.material3
) Card
并且 elevation
属性需要 CardElevation
对象:
类似:
Card(
shape = RoundedCornerShape(20.dp),
elevation = CardDefaults.cardElevation(
defaultElevation = 10.dp
)
)
我们可以使用以下方式在Android compose中给卡片赋予高度
Card(elevation = CardDefaults.cardElevation(
defaultElevation = 10.dp))
并导入
import androidx.compose.material3.Card
我能够使用这个语法:
卡(标高 = CardDefaults.cardElevation(10.dp))
Card(modifier = modifier.fillMaxWidth(),
shape = RoundedCornerShape(15.dp),
elevation = CardDefaults.cardElevation(
defaultElevation = 5.dp))
)