简体   繁体   English

在Flex网格中更改列宽

[英]Change column width in Flex Grid

I'm using a mx.containers.Grid to layout some data, and the last column is a set of checkboxes. 我正在使用mx.containers.Grid来布局一些数据,最后一列是一组复选框。 MXML Code snippet: MXML代码段:

<mx:Grid width="95%" height="50%">
  <mx:GridRow id="row1">
    <mx:GridItem>
      <mx:Label id="label1" ... />
    </mx:GridItem>
    <mx:GridItem>
      <mx:Label id="textValue1" ... />
    </mx:GridItem>
    <mx:GridItem>
      <mx:CheckBox id="checkBox1" />
    </mx:GridItem>
  </mx:GridRow>
  <mx:GridRow id="row2">
    <mx:GridItem>
      <mx:Label id="label2" ... />
    </mx:GridItem>
    <mx:GridItem>
      <mx:Label id="textValue2" ... />
    </mx:GridItem>
    <mx:GridItem>
      <mx:CheckBox id="checkBox2" />
    </mx:GridItem>
  </mx:GridRow>
  <mx:GridRow id="row3">
    <mx:GridItem>
      <mx:Label id="label3" ... />
    </mx:GridItem>
    <mx:GridItem>
      <mx:Label id="textValue3" ... />
    </mx:GridItem>
    <mx:GridItem>
      <mx:CheckBox id="checkBox3" />
    </mx:GridItem>
  </mx:GridRow>
</mx:Grid>

Basically, I want the labels & text values to align however the Grid component sees fit. 基本上,我希望标签和文本值对齐,但是Grid组件认为合适。 However, I'd like the checkboxes to be right-aligned. 但是,我希望复选框是右对齐的。 I've tried setting the width of the textValues to 100% and it does nothing. 我尝试将textValues的宽度设置为100%,但它什么也不做。 I don't want to use hard-coded pixel values/canvases/etc because it is important that this is easy to change/update. 我不想使用硬编码的像素值/画布/等,因为这很容易更改/更新,这一点很重要。

I found a solution, but it is kind-of a hack. 我找到了解决方案,但这有点像黑客。 But I'll post it for people who are having the same problem as I was: 但我会将其发布给遇到与我相同的问题的人:

<mx:Grid width="95%" height="50%">
  <mx:GridRow id="row1" width="100%">
    <mx:GridItem>
      <mx:Label id="label1" ... />
    </mx:GridItem>
    <mx:GridItem>
      <mx:Label id="textValue1" ... />
    </mx:GridItem>
    <mx:GridItem>
      <mx:CheckBox id="checkBox1" width="100%" horizontalAlign="right" />
    </mx:GridItem>
  </mx:GridRow>
  <mx:GridRow id="row2" width="100%">
    <mx:GridItem>
      <mx:Label id="label2" ... />
    </mx:GridItem>
    <mx:GridItem>
      <mx:Label id="textValue2" ... />
    </mx:GridItem>
    <mx:GridItem>
      <mx:CheckBox id="checkBox2" width="100%" horizontalAlign="right"/>
    </mx:GridItem>
  </mx:GridRow>
  <mx:GridRow id="row3" width="100%">
    <mx:GridItem>
      <mx:Label id="label3" ... />
    </mx:GridItem>
    <mx:GridItem>
      <mx:Label id="textValue3" ... />
    </mx:GridItem>
    <mx:GridItem>
      <mx:CheckBox id="checkBox3" width="100%" horizontalAlign="right"/>
    </mx:GridItem>
  </mx:GridRow>
</mx:Grid>

Basically, add 'width="100%"' to every GridRow, and then add 'width="100%" horizontalAlign="right"' to every GridItem you want to be right-aligned. 基本上,将'width =“ 100%”'添加到每个GridRow,然后将'width =“ 100%” horizo​​ntalAlign =“ right”'添加到您要右对齐的每个GridItem。

尝试将GridRow / GridItem的宽度也设置为100%。

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

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