Jetpack Compose中卡片的圆角为什么不均匀?

6

我有一个 lazyColumn,它包含一些项目。

@Composable
fun MySimpleListItem(
    itemViewState: String,
    itemClickedCallback: (() -> Unit)? = null,
) {
    Card(
        shape = RoundedCornerShape(50.dp),
        backgroundColor = Color(0xFFFF0000),
    ) {
        Text(
            text = itemViewState,
            modifier = Modifier.fillMaxWidth().padding(16.dp),
            style = TextStyle(fontSize = 32.sp),
            textAlign = TextAlign.Center
        )
    }
}

看起来顶部和底部的角落圆弧不同。我做错了什么吗? enter image description here
1个回答

20

您的卡片高度太小,无法正确显示形状。它应该至少是半径的两倍大小。

Card(
    modifier = Modifier.preferredHeight(100.dp),
    shape = RoundedCornerShape(50.dp),
    backgroundColor = Color(0xFFFF0000),
)

或者将您的形状半径设置为百分比:

Card(
    shape = RoundedCornerShape(50),
    backgroundColor = Color(0xFFFF0000),
    )

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接