我想添加背景图像,但如果我在 Box 内仅添加 Image(){} ,则背景图像的大小无法调整到内容并包含我想要的更多空间。我发现了这个,但对我不起作用,https://www.tutorialkart.com/android-jetpack-compose/card-background-image/ 因为我想要将图像调整为列
Card() {
Image(painter = painterResource(id = R.drawable.flower), contentDescription = null)
Column(modifier = Modifier.padding(10.dp)) {
Text("AB CDE", fontWeight = FontWeight.W700)
Text("+0 12345678")
Text("XYZ city", fontWeight = FontWeight.W300)
}
}
最佳答案
您可以利用 Box
范围内可用的 matchParentSize
修饰符并缩放图像以适合容器。
Card {
Box {
Image(
painter = painterResource(id = R.drawable.flower),
contentDescription = "null",
modifier = Modifier
.matchParentSize(),
contentScale = ContentScale.Crop
)
Column(modifier = Modifier.padding(10.dp)) {
Text("AB CDE", fontWeight = FontWeight.W700)
Text("+0 12345678")
Text("XYZ city", fontWeight = FontWeight.W300)
}
}
}
关于android - 在 Jetpack Compose 中是否可以将背景图像添加到填充所有列的列(如填充颜色)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73108402/