Apache – Flex layout 2 objects with first one centered

apache-flexflex3

I have two labels (A and B) in a Flex VBox, with the horizontal alignment set to "center". I'd like to set A to be vertically centered (in the exact center of the container) and B to be underneath A (or on the bottom; either will do). What's the best way to rig this?

Best Answer

I found that using a grid control works very nicely to accomplish the task, and without adding in blank labels:

<mx:Grid width="100%" height="100%">
  <mx:GridRow height="20%"/>
  <mx:GridRow height="60%">
    <mx:GridItem verticalAlign="middle" horizontalAlign="center">
      <mx:Label text="Label A" fontSize="60" fontFamily="Arial"/>   
    </mx:GridItem>
  </mx:GridRow>
  <mx:GridRow height="20%" verticalAlign="middle">
    <mx:GridItem verticalAlign="middle" horizontalAlign="center">
      <mx:Label text="Label B" fontSize="24" fontFamily="Arial"/>
    </mx:GridItem>
  </mx:GridRow>         
</mx:Grid>
Related Topic