答案 0 :(得分:24)
有一个 clip 修饰符可以应用于任何可组合以及 Image
,只需将 CircleShape
传递给它:
Image(
painter = painterResource(R.drawable.sample_avatar),
contentDescription = "avatar",
contentScale = ContentScale.Crop, // crop the image if it's not a square
modifier = Modifier
.size(64.dp)
.clip(CircleShape) // clip to the circle shape
.border(2.dp, Color.Gray, CircleShape) // add a border (optional)
)
您可以使用任何其他形状来裁剪图像,例如 CircleShape
它只是 RoundedCornerShape(percent = 50)
。让我们试试RoundedCornerShape(percent = 10)
: