6 Replies Latest reply on Oct 19, 2009 4:31 PM by saveth

    Align Label Left and Button Right?

    saveth

      I'm not sure why I'm having such issues trying to get this to work. I just want to align a label left and button right inside of a HGroup. Here is my current code that doesn't work.

       

      <s:HGroup width="100%">
      <s:Label styleName="header" text="Deductions, Credits &amp; Payments" />
      <s:Button click="currentState='Normal';" includeIn="DeductionsCreditAndPayments" label="Done" right="0" />
      </s:HGroup>
      

       

      Thanks for any help you can give,

      Brian

        • 1. Re: Align Label Left and Button Right?
          Shongrunden Adobe Employee

          HGroup/VGroup doesn't currently respect top/left/right/bottom constraints placed on its elements.

           

          Could you get by using a Group instead?

           

          <s:Group width="100%">
              <s:Label left="0" text="One" />
              <s:Label right="0" text="Two" />
          </s:Group>

          • 2. Re: Align Label Left and Button Right?
            David_F57 Level 5

            Hi,

            Hgroup automatically left aligns components so it isn't ideal for right aligning, you would be better of with a normal group and set the left and right properties of the components.

             

            David

            1 person found this helpful
            • 3. Re: Align Label Left and Button Right?
              saveth Level 1

              Thanks, this works perfect. Any reason why Adobe doesn't code it so that the left and right properties override the containers alignment properties?

              • 4. Re: Align Label Left and Button Right?
                Shongrunden Adobe Employee

                HGroup is basically a Group with a HorizontalLayout.

                 

                HorizontalLayout/VerticalLayout does not respect the top/left/right/bottom constraints of the elements they are laying out.

                 

                It is possible that we might some day allow constraints on the minor axis, for example:

                 

                <s:HGroup>
                    <s:Button label="1" />
                    <s:Button label="1" top="20" bottom="20" />
                </s:HGroup

                 

                But I believe this won't be happening for the Flex 4 timeframe.

                 

                What you are looking for is to have the HorizontalLayout respect constraints on the major axis of the layout which I doubt we plan on doing.  The point of a HorizontalLayout is to layout elements one after the other from left to right.  For example, setting left="0" on the last element would mean that you want the last element to be positioned at the leftmost position on top of the first element.  In this case you don't actually want a HorizontalLayout, but should use a BasicLayout (absolute positioning) or write a custom layout to handle this case.

                 

                If you would prefer to stick with an HGroup then you might also try using a spacer with 100% width:

                 

                <s:HGroup width="100%">
                    <s:Button label="left" />
                    <mx:Spacer width="100%" />
                    <s:Button label="right" />
                </s:HGroup>

                1 person found this helpful
                • 5. Re: Align Label Left and Button Right?
                  GordonSmith Level 4

                  HGroup doesn't pay attention to constraint styles like 'left' and 'right'... it lays out its children horizontally in order. You need to use <s:Group>, whose default layout is BasicLayout rather than HorizontalLayout; BasicLayout understands the constraint styles.

                   

                  Gordon Smith

                  Adobe Flex SDK Team

                  • 6. Re: Align Label Left and Button Right?
                    saveth Level 1

                    Thanks for the clarification. In ways this makes sense. I always try to do things in the least amount of syntax or coding possible so you can't blame me for trying