Centering Content in Flex 4 - apache-flex

I'm building a custom component that extends SkinnableContainer. I can center the content either vertically or horizontally inside it, but not both-- and that is what I need.
I'm setting the layout to HorizontalLayout for the component and setting verticalAlign to middle.
Then I'm creating a canvas to surround another component that goes inside this component, and setting that canvas width to 100%, and then setting textAlign=center, but no dice.
Any help is appreciated.

Use the horizontalCenter and verticalCenter properties to center your groups. The value is the number of pixels from either center where the sign of value denotes direction, 0 is absolute center.
This'll do the trick (assuming you want horizontal layout for your items). The 's' namespace refers to the spark components, since you're asking about flex 4 I assume Halo isn't of interest.
<s:Group>
<!-- Any parent with BasicLayout will acknowledge horizontalCenter and verticalCenter -->
<s:layout>
<s:BasicLayout />
</s:layout>
<s:Group horizontalCenter="0" verticalCenter="0">
<s:layout>
<s:HorizontalLayout/>
</s:layout>
<s:Button />
<s:Button />
<s:Button />
</s:Group>
</s:Group>

Related

How to make an image align with the baseline in a horizontal layout?

I have the following s:HorizontalLayout that works great for all controls except the Image and BitmapImage controls. They do not align vertically. The rest of the controls are aligned along the baseline but the images are sitting way below the other controls. Is there a way I can set the baseline of the images and adjust their vertical position?
<s:Group>
<s:layout>
<s:HorizontalLayout paddingLeft="4" verticalAlign="baseline"/>
</s:layout>
<s:CheckBox label="Test"/>
<s:CheckBox label="Select"/>
<s:BitmapImage source="{MyIcon}" height="18"/>
<s:Image source="{MyIcon}" height="18"/>
<s:Label id="topLocation" minWidth="65"/>
</s:Group>

Flex horizontal layout that wraps to the next line?

Is there a Flex layout class that wraps to the next line and does not size all the items the same size?
I've tried using TileLayout but the problem with that is that all the items are sized to the largest item. I want to set the gap between each to be consistent. Basically a variableColumnWidth type of feature.
<s:List id="exampleList"
selectedIndex="0"
width="100%"
dataProvider="{examplesCollection}"
change="exampleList_changeHandler(event)"
height="250"
>
<s:layout>
<s:TileLayout verticalGap="0" horizontalGap="0" />
</s:layout>
</s:List>
I'm using Apache Flex 4.12.
I think that the quickest way would be to implement an item renderer, like this example. The other option is to implement your own layout which you can adapt to what you need, for this you need to understand very well how layouts work.

FLEX scrollable NavigatorContent

I have a TabNaivgator which I fill in runtime with NavigatorContent filled in runtime as well with content.
I see though that my content is taller than the NavigatorContent height, but instead of creating a scrollbar, Flex makes the content exit the NavigatorContent bounds
here is the code: http://pastebin.com/xxnSz6pk
and here is the result: http://dl.dropbox.com/u/4064417/Immagine.png
how do I make that content scroll?
thanx in advance
Use the Scroller component inside the NavigationContent tags, and a Group inside the Scroller tags:
<s:NavigatorContent width="100%" height="100%">
<s:Scroller width="100%" height="100%">
<s:Group>
<!-- Your component(s) here! -->
</s:Group>
</s:Scroller>
</s:NavigatorContent>

Add padding to a titlewindow in Flex 4 (ideally using skins)?

By default TitleWindows seem to have no padding. I tried the properties "left", "right" etc and it doesn't work. Actually I'd like to have a default for my whole app, so I tried creating a skin but no matter where in the skin I add 'left="50"' it just doesn't create padding on the left. You'd think that you should add it to the element with id="contentGroup", as described on this Adobe Skinning help page, but that does not work.
Surely this is something almost everyone wants to do?
The contentGroup in the default TitleWindowSkin is inside a VerticalLayout which does not respect top/left/right/bottom constraints.
You could do this by duplicating the default TitleWindowSkin and wrapping the contentGroup with a Group with width/height of 100%:
...
<s:Group width="100%" height="100%">
<!--- #copy spark.components.SkinnableContainer#contentGroup -->
<s:Group id="contentGroup" top="10" left="10" right="10" bottom="10" minWidth="0" minHeight="0" />
</s:Group>
...
Since the TitleWindow extends the Panel component, it doesn't support the padding properties a HGroup or VGroup based component would. As far as I know, there's no way to skin a TitleWindow so that the padding properties are automatically set.
All I do is set the x and y coordinates of my components within the TitleWindow so that they are laid out where I want them.

Float left or right in layouts or containers?

[Flex 4] Float left or right in layouts or containers?
i have a main container, that is dynamic, 100% width, and in it there are 3 components. one should be floating to left, to right and the other will be centered. how do i do that?
What do you mean by float? Is there any reason a group with a HorizontalLayout won't work?
<s:group layout="{new HorizontalLayout()}" width="100%>
<container1>
<container2>
<container2>
</s:group>
Add your 3 components to an HGroup (spark) or an HBox (halo). If you want dividers that allow your components to be resized, you can use an HDividedBox. Hope that helps.
Edit: Here's a code example based on your comment:
<s:HGroup width="100%">
<s:Panel id="fixedPanel1" width="150"/>
<s:Panel id="variablePanel" width="100%"/>
<s:Panel id="fixedPanel2" width="150"/>
</s:HGroup>
Is this what your are looking for?

Resources