Jetpack Compose Row 中的等宽元素
在 Jetpack Compose 中使 Row
的所有子项的宽度相同的最简单方法是什么?例如,如果 Row
中有 4 个 Box
元素,我希望每个 Box
的宽度为 1/4(减去填充)整行的。
What is the easiest way to make the width the same for all the children of a Row
in Jetpack Compose? For example, if there are 4 Box
elements within a Row
, I want each Box
to have 1/4 the width (minus the padding) of the entire row.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用修饰符。包含最大宽度并向框添加重量的行
,例如,
You can use modifier. Row which contains max width and add weight to the box like
For example,
在行上使用
spacedBy
属性,在子项上使用weight
修饰符。查看下面的示例:Use
spacedBy
attribute on Row andweight
modifier on children. Checkout the below example:对所有元素使用 weight 修饰符。
Modifier.weight(1)
use the weight modifier..
Modifier.weight(1)
on all the elements您可以对该行的子行使用
Modifier.weight(1f)
。一个很好的例子是这 3 个不同长度的文本。
我们只需应用
Modifier.weight (1F)
即可使宽度相同,尽管字符数量不同。You can use
Modifier.weight(1f)
on the row's children.A good example is these 3 Texts with different lengths.
We simply apply
Modifier.weight (1F)
to make the width the same despite the different number of characters.