gpt4 book ai didi

android - 如何使元素填充Jetpack Compose中行或列内的剩余空间

转载 作者:行者123 更新时间:2023-12-03 22:59:57 25 4
gpt4 key购买 nike

我试图连续显示两条文本消息,但是当第一个文本的大小很大时,第二个 View 被推出屏幕,如下所示:
编码:

Row(modifier = Modifier.fillMaxWidth()) {
Text(
text = "safasfasdfsasdssdsaasdsadsdsaasdsasdsasdasddassdsssdasdadsasdasdsd",
modifier = Modifier
.padding(top = 12.dp, bottom = 12.dp, end = 12.dp, start = 10.dp)
.background(Color.Gray)
)
Text(
text = "12:00 am",
style = messageTimeTextStyle,
modifier = Modifier
.padding(horizontal = 16.dp),
maxLines = 1
)
}

输出:
enter image description here

最佳答案

您可以申请 weight 修饰符 仅限 到长文本。.weight修饰符调整元素的宽度,使其与 Row 中其他加权同级元素的权重成正比。 .父级将分割剩余的水平空间测量未加权子元素后并按照这个重量分配
就像是:

Row() {
Text(text = "safasfasdfsasdssdsaasdsadsdsaasdsasdsasdasddassdsssdasdadsasdasdsd",
Modifier
.padding(top = 12.dp, bottom = 12.dp, end = 12.dp, start = 10.dp)
.background(Color.Gray)
.weight(1f)
)
Text(
text = "12:00 am",
modifier = Modifier
.padding(horizontal = 16.dp),
maxLines = 1
)
}
enter image description here
或者
Row() {
Column(Modifier.weight(1f)){
Text(text = "safasfasdfsasdssdsaasdsadsdsa.." , ....)
}
Column() {
Text( text = "12.00 ..", .....)
}
}

关于android - 如何使元素填充Jetpack Compose中行或列内的剩余空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66622282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com