简体   繁体   English

设置最大约束宽度以组合放置在其他固定大小的小部件之间的小部件

[英]Set max constraint width to compose widget placed between other fix sized widgets

I'm trying to make a layout like on the scheme below:我正在尝试按照以下方案进行布局:

在此处输入图像描述

I've already found a solution with a weighted Row() inside other Row() .我已经在其他Row()中找到了一个加权Row()的解决方案。 But it looks too complicated for such a simple problem.但是对于这样一个简单的问题,它看起来太复杂了。

Row() {
    Icon()                                    // Fix width
    Row(modifier = Modifier.weight(1f)) {
        Text(modifier = Modifier.weight(1f))  // Max width
        Icon()                                // Fix width
    }
}

Surely many have faced such an issue.肯定很多人都遇到过这样的问题。 Are there more beautiful ways to solve it?有没有更漂亮的方法来解决它?

You need not use a nested Row here.您不需要在这里使用嵌套的 Row。 Just give the weight(1f) modifier to center element.只需将weight(1f)修饰符赋予中心元素。

Row {
    Icon() // View 1 (Fix width)
    CenterPiece(
        modifier = Modifier
            .weight(1f)
            .padding(horizontal = 8.dp)  // For the spacing between components
    )
    Icon() // View 3 (Fix width)                               
}

You might also want to add verticalAlignment = Alignment.CenterVertically to the Row so that the three components are centered vertically.您可能还想将verticalAlignment = Alignment.CenterVertically添加到Row中,以便三个组件垂直居中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM