如何使用Material3在jetpack compose中设置卡片高度

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

我在jetpack compose中创建了简单的卡片,在这里我设置了海拔,但它显示类型不匹配。

Card(
            shape = RoundedCornerShape(20.dp),elevation = 10.dp
        ) {
            Box(modifier = Modifier.height(200.dp)) {
                Image(painter = painter, contentDescription = contentDescription,
                contentScale = ContentScale.Crop)
            }

    }

android android-jetpack-compose android-jetpack android-cardview android-compose-card
4个回答
134
投票

您正在使用 M3 (

androidx.compose.material3
)
Card
并且
elevation
属性需要
CardElevation
对象:

类似:

Card(
    shape = RoundedCornerShape(20.dp),
    elevation = CardDefaults.cardElevation(
        defaultElevation = 10.dp
    )
)

2
投票

我们可以使用以下方式在Android compose中给卡片赋予高度

Card(elevation = CardDefaults.cardElevation(
    defaultElevation = 10.dp))

并导入

import androidx.compose.material3.Card

0
投票

我能够使用这个语法:

卡(标高 = CardDefaults.cardElevation(10.dp))


0
投票
Card(modifier = modifier.fillMaxWidth(),
       shape = RoundedCornerShape(15.dp),
       elevation = CardDefaults.cardElevation(
      defaultElevation = 5.dp))
)
© www.soinside.com 2019 - 2024. All rights reserved.