我想在行中的框的 BottomEnd 中对齐按钮(在波纹管卡的 BottonEnd 中)。我有 Card with Row,分为两部分 - Card 和 Box,我希望 Box 最多填充该行的其余部分。我无法按照自己的意愿实现它。下面我附上了当前代码的可视化。
.
@Composable
fun ProductItem(product: ProductModel, onItemClick: () -> Unit, onAddToCardButton: () -> Unit) {
Card(
modifier = Modifier
.fillMaxSize()
.padding(7.dp)
.clickable { onItemClick() },
shape = MaterialTheme.shapes.large,
elevation = 4.dp
) {
Row(
modifier = Modifier.fillMaxSize()
) {
Card(
modifier = Modifier
.weight(1f),
shape = MaterialTheme.shapes.small,
elevation = 2.dp
) {
Image(
painter = painterResource(id = R.drawable.ic_splash_screen),
contentDescription = "Image of ${product.name}",
)
}
Box(
modifier = Modifier
.weight(2f)
.fillMaxHeight()
.padding(6.dp)
.background(Color.Green)
) {
Column(modifier = Modifier.align(Alignment.TopStart)) {
Text(
text = "${product.number}. ${product.name}",
fontWeight = FontWeight.Bold,
style = MaterialTheme.typography.h4,
)
Text(
text = product.ingredients, fontStyle = FontStyle.Italic
)
}
Button(
modifier = Modifier.align(Alignment.BottomEnd),
onClick = {
onAddToCardButton()
},
shape = RoundedCornerShape(8.dp),
) {
if (product.type == "pizza") {
Text(text = "od ${String.format("%.2f", product.price[0])} zł")
} else {
Text(text = "${String.format("%.2f", product.price[0])} zł")
}
}
}
}
}
}
最佳答案
我希望您在 LazyColumn
或垂直滚动条中显示此项。
Modifier.fillMaxHeight
在这种情况下不起作用,因为父高度约束等于无穷大。
要解决这个问题,您可以使用静态值,但在本例中为 intrinsic measurements可用于包装内容大小。
将 Modifier.height(IntrinsicSize.Max)
添加到您的 Row
。
关于android - 如何 fillMaxSize() Box() inside row - Compose,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71856677/