Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex HBox alignment

I experimenting with Flex Styling, and I came across an alignment issue.

I have two image components inside an HBox, and the HBox inside a Canvas, which in turn is inside the main Application.

<mx:Canvas id="Navigation"
    horizontalCenter="0"
    bottom="0"
    left="0"
    right="0"
    visible="true"
    height="40"
    styleName="transparent">

    <mx:HBox 
        styleName="ControlContainer"
        horizontalCenter="0"
        width="150">

        <mx:Image id="left"
            source="@Embed(source='left.png')"
            left="0"/>

        <mx:Image id="right"
            source="@Embed(source='right.png')"
            right="0"/>
    </mx:HBox>
</mx:Canvas>

Custom CSS:

    .transparent {
        backgroundAlpha: 0.7;
        background-color: white;
    }
    .ControlContainer {

    }

Well as you see I gave the Canvas with background, and a bit transparency.

But the then there is an HBox, with 150px width, and two images inside it, each image is 40x40, so in this case the HBox would be 150x40 which is nice for what I'm trying to do.

But both images are side by side, and i want the left image aligned to the left side of the HBox, and the right image to the right side.

I've tried text-align but nothing, my guess is that Flex CSS doesn't behave the same way as CSS focused to HTML.

So how can i do that?

PS: If someone knows some good websites about Flex Styling, Flex CSS or Flex customization, would be great if you leave me a few links in comment.

like image 492
Fábio Antunes Avatar asked Nov 12 '09 19:11

Fábio Antunes


2 Answers

Spacer tags are useful in situations like these. If you insert one in-between the two images, you can push them to edges of the HBox. While setting the spacer's width to 100% would seem to indicate that it's going to take up the entire box, this won't be the case as the images' widths will be set to an absolute value as soon as their content has loaded. The spacer will then take up 100% of the remaining width.

    <mx:HBox 
            styleName="ControlContainer"
            horizontalCenter="0"
            width="150">

            <mx:Image id="left"
                    source="@Embed(source='left.png')"
                    left="0"/>

            <mx:Spacer width="100%"/>

            <mx:Image id="right"
                    source="@Embed(source='right.png')"
                    right="0"/>
    </mx:HBox>
like image 149
Stiggler Avatar answered Sep 19 '22 13:09

Stiggler


You can try these websites

http://www.adobe.com/devnet/flex/quickstart/styling_components/

http://www.loscavio.com/downloads/blog/flex3_css_list/flex3_css_list.htm

I have not had much experience with CSS Styling in Flex i would usually just tell the HBox HorizontalAlign="left" etc

I am not sure you will be able to align two different images in two different directions inside the same HBox

I would recommend adding two Hbox's both 100% height and 50% width each and align them separate.

like image 22
medoix Avatar answered Sep 22 '22 13:09

medoix