I'm trying to learn Flex layout using VGroup and HGroup. As a simple exercise, I want to control the pixel-placement of button pairs. The code below attempts to place 3 pairs of buttons each in two rows. For example, the first row has a button pair 20 pixels from the top and left; another button pair 20 pixels from the top and centered; and another button pair 20 pixels from the top and right. The 2nd row has just all the buttons aligned 20 pixels to left.
It should look something like:
button button button button button button
button button button button button button
But the code produces no difference between the two rows. Can anyone help me understand how to control the layout like I'm intending?
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955"
minHeight="600">
<s:VGroup top="20" left="20" right="20">
<s:HGroup top="20" left="20" right="20">
<s:Button label="row1 left1"/>
<s:Button label="row1 left2"/>
<s:HGroup horizontalAlign="center">
<s:Button label="row1 middle1"/>
<s:Button label="row1 middle2"/>
</s:HGroup>
<s:HGroup right="20">
<s:Button label="row1 right1"/>
<s:Button label="row1 right2"/>
</s:HGroup>
</s:HGroup>
<s:HGroup top="50" left="20">
<s:Button label="row2 left1"/>
<s:Button label="row2 left2"/>
<s:Button label="row2 middle1"/>
<s:Button label="row2 middle2"/>
<s:Button label="row2 right1"/>
<s:Button label="row2 right2"/>
</s:HGroup>
</s:VGroup>
</s:Application>
UPDATE: Based on Dom's answer below, here's the correct code for what I was intending:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955"
minHeight="600">
<s:HGroup left="20" right="20" top="20">
<s:HGroup>
<s:Button click=""/>
<s:Button click=""/>
</s:HGroup>
<s:Spacer width="100%"/>
<s:HGroup>
<s:Button click=""/>
<s:Button click=""/>
</s:HGroup>
<s:Spacer width="100%"/>
<s:HGroup>
<s:Button click=""/>
<s:Button click=""/>
</s:HGroup>
</s:HGroup>
<s:VGroup left="20" right="20" top="50">
<s:HGroup width="100%">
<s:Button click=""/>
<s:Button click=""/>
<s:Button click=""/>
<s:Button click=""/>
<s:Button click=""/>
<s:Button click=""/>
</s:HGroup>
</s:VGroup>
</s:Application>
I see two options:
1: dont use HGroup's
2: use HGroup's and space the items with
<s:Spacer width="x"/>
where x can be a % or exact pixels.
edit: properly formatted my answer so that s:spacer showed
edit 2: added code below:
<s:VGroup width="100%" height="100%">
<s:HGroup width="100%">
<s:HGroup>
<s:Button click=""/>
<s:Button click=""/>
</s:HGroup>
<s:Spacer width="100%"/>
<s:HGroup>
<s:Button click=""/>
<s:Button click=""/>
</s:HGroup>
<s:Spacer width="100%"/>
<s:HGroup>
<s:Button click=""/>
<s:Button click=""/>
</s:HGroup>
</s:HGroup>
<s:HGroup width="100%">
<s:Button click=""/>
<s:Button click=""/>
<s:Button click=""/>
<s:Button click=""/>
<s:Button click=""/>
<s:Button click=""/>
</s:HGroup>
</s:VGroup>
That will look exactly like your example above.
I really try to avoid spacers. I think I've used one once to hack something into place... but it felt dirty.
The first row shouldn't be an HGroup, but a Group comprised of three HGroups. Like this, but without any spacers:
<s:VGroup top="20" left="20" right="20">
<s:Group width="100%">
<s:HGroup left="0">
<s:Button label="row1 left1"/>
<s:Button label="row1 left2"/>
</s:HGroup>
<s:HGroup horizontalCenter="0">
<s:Button label="row1 middle1"/>
<s:Button label="row1 middle2"/>
</s:HGroup>
<s:HGroup right="0">
<s:Button label="row1 right1"/>
<s:Button label="row1 right2"/>
</s:HGroup>
</s:Group>
<s:HGroup top="50" left="20">
<s:Button label="row2 left1"/>
<s:Button label="row2 left2"/>
<s:Button label="row2 middle1"/>
<s:Button label="row2 middle2"/>
<s:Button label="row2 right1"/>
<s:Button label="row2 right2"/>
</s:HGroup>
</s:VGroup>
Related
I have a TabNavigator and before that a ViewStack with TabBar that would not clip it's contents. It over flows the border or appears under other components positioned further down the screen. Has anyone run into this before?
Here is my code:
<mx:VDividedBox width="300" height="100%">
<mx:TabNavigator id="firstViewStack"
borderStyle="solid"
width="100%"
height="100%"
clipContent="true">
<s:NavigatorContent id="content1"
label="ITEMS">
<views:Items height="550" width="100%" />
</s:NavigatorContent>
<s:NavigatorContent id="eventsContent" label="ITEMS 2">
<views:Items height="880" width="100%"/>
</s:NavigatorContent>
</mx:TabNavigator>
</mx:VDividedBox>
UPDATE
I've included a animated gif of me resizing the tab content. As you can see the mask appears to be sized to the content rather than the available area??? Notice the border of the tab navigator along the size is being overlapped when resizing.
I set the minimum height on all of the content to lower values and height to 100% on all the content so it is not as high but you can see the content is still not getting clipped.
I also tried with a VGroup rather than a VDividedBox and it doesn't matter.
Here is another code example:
<s:VGroup top="50" left="50" width="400">
<mx:TabNavigator width="100%" height="300">
<s:NavigatorContent label="TAB">
<s:Group width="100%" height="400">
<s:Rect width="100%" height="100%">
<s:fill>
<s:SolidColor color="#ff0000"/>
</s:fill>
</s:Rect>
</s:Group>
</s:NavigatorContent>
<s:NavigatorContent label="TAB">
<s:Group width="100%" height="400">
<s:Rect width="100%" height="100%">
<s:fill>
<s:SolidColor color="#0000ff"/>
</s:fill>
</s:Rect>
</s:Group>
</s:NavigatorContent>
</mx:TabNavigator>
<s:Button width="100%" label="HELLO WORLD"/>
<s:Button width="100%" label="HELLO WORLD"/>
</s:VGroup>
I have implemented 2 approaches - one with a Scroller and another with autosize.
Here is an example
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600">
<s:HGroup width="100%" height="100%" left="50" top="50">
<!-- Using Scroller-->
<s:VGroup width="400">
<mx:TabNavigator width="100%" height="300">
<s:NavigatorContent label="TAB" width="100%" height="100%">
<s:Scroller width="100%" height="100%">
<s:Group>
<s:Group width="100%" height="400">
<s:Rect width="100%" height="100%">
<s:fill>
<s:SolidColor color="#ff0000"/>
</s:fill>
</s:Rect>
</s:Group>
</s:Group>
</s:Scroller>
</s:NavigatorContent>
<s:NavigatorContent label="TAB" width="100%" height="100%">
<s:Scroller width="100%" height="100%">
<s:Group>
<s:Group width="100%" height="600">
<s:Rect width="100%" height="100%">
<s:fill>
<s:SolidColor color="#0000ff"/>
</s:fill>
</s:Rect>
</s:Group>
</s:Group>
</s:Scroller>
</s:NavigatorContent>
</mx:TabNavigator>
<s:Button width="100%" label="HELLO WORLD"/>
<s:Button width="100%" label="HELLO WORLD"/>
</s:VGroup>
<s:Spacer width="60"/>
<!-- Using Autosize-->
<s:VGroup top="50" left="50" width="400">
<mx:TabNavigator width="100%" minHeight="300" resizeToContent="true" >
<s:NavigatorContent label="TAB" width="100%" height="100%">
<s:Group width="100%" height="400">
<s:Rect width="100%" height="100%">
<s:fill>
<s:SolidColor color="#ff0000"/>
</s:fill>
</s:Rect>
</s:Group>
</s:NavigatorContent>
<s:NavigatorContent label="TAB" width="100%" height="100%">
<s:Group width="100%" height="500">
<s:Rect width="100%" height="100%">
<s:fill>
<s:SolidColor color="#0000ff"/>
</s:fill>
</s:Rect>
</s:Group>
</s:NavigatorContent>
</mx:TabNavigator>
<s:Button width="100%" label="HELLO WORLD"/>
<s:Button width="100%" label="HELLO WORLD"/>
</s:VGroup>
</s:HGroup>
</s:Application>
If you run the following mxml code, you'll see the MyLabel1 is sitting higher than the other labels (e.g. MyLabel2) and other items on the 2nd row.
How to change the code so MyLabel1 sits in-line with MyLabel2, etc?
Note that any changes need to keep the group of MyLabel2, MyLabel3, and MyButton3 to be equally spaced between MyLabel1 (on the left) and MyLabel4 (on the right), as it is now. In other words, this middle group on the 2nd row is NOT centered in the container, but has equal space on it's left and right.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="200" minHeight="300">
<s:VGroup top="10" left="20" right="20">
<s:Group width="100%">
<s:HGroup left="0" top="5" verticalAlign="baseline">
<s:Label text="Some Text Here" />
</s:HGroup>
<s:HGroup right="0" verticalAlign="baseline">
<s:Button label="Button1" width="65"/>
<s:Button label="Button2" width="65"/>
</s:HGroup>
</s:Group>
<s:Spacer height="2"/>
<s:HGroup width="100%" >
<s:HGroup >
<s:Label text="MyLabel1"/>
</s:HGroup>
<s:Spacer width="100%"/>
<s:HGroup verticalAlign="baseline">
<s:Label text="MyLabel2"/>
<s:Label text="MyLabel3"/>
<s:Button label="MyButton3" width="85"/>
</s:HGroup>
<s:Spacer width="100%"/>
<s:HGroup verticalAlign="baseline">
<s:Label text="MyLabel4"/>
<s:TextInput id="myID" />
</s:HGroup>
</s:HGroup>
</s:VGroup>
Try:
set the three hgroup verticalAlign to middle so the item contained are positioned in the middle of the height of the component...
then you need to specify an height for the three hgroup because:
- in the first there is only a label (with a certain height)
- in the others two there are a button and a textinput that has a greater height than the simple label (hgroup 1)
Using a custom height for the group override the height set by the inner components
<s:VGroup top="10" left="20" right="20">
<s:Group width="100%">
<s:HGroup left="0" top="5" verticalAlign="baseline">
<s:Label text="Some Text Here" />
</s:HGroup>
<s:HGroup right="0" verticalAlign="baseline">
<s:Button label="Button1" width="65"/>
<s:Button label="Button2" width="65"/>
</s:HGroup>
</s:Group>
<s:Spacer height="2"/>
<s:HGroup width="100%" >
<s:HGroup verticalAlign="middle" height="25">
<s:Label text="MyLabel1"/>
</s:HGroup>
<s:Spacer width="100%"/>
<s:HGroup verticalAlign="middle" height="25">
<s:Label text="MyLabel2"/>
<s:Label text="MyLabel3"/>
<s:Button label="MyButton3" width="85"/>
</s:HGroup>
<s:Spacer width="100%"/>
<s:HGroup verticalAlign="middle" height="25">
<s:Label text="MyLabel4"/>
<s:TextInput id="myID" />
</s:HGroup>
</s:HGroup>
</s:VGroup>
Just add verticalAlign="baseline" to most outer HGroup.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:VGroup top="10" left="20" right="20">
<s:Group width="100%">
<s:HGroup left="0" top="5" verticalAlign="baseline">
<s:Label text="Some Text Here" />
</s:HGroup>
<s:HGroup right="0" verticalAlign="baseline">
<s:Button label="Button1" width="65"/>
<s:Button label="Button2" width="65"/>
</s:HGroup>
</s:Group>
<s:Spacer height="2"/>
<s:HGroup width="100%" verticalAlign="baseline" >
<s:HGroup>
<s:Label text="MyLabel1"/>
</s:HGroup>
<s:Spacer width="100%"/>
<s:HGroup verticalAlign="baseline">
<s:Label text="MyLabel2"/>
<s:Label text="MyLabel3"/>
<s:Button label="MyButton3" width="85"/>
</s:HGroup>
<s:Spacer width="100%"/>
<s:HGroup verticalAlign="baseline">
<s:Label text="MyLabel4"/>
<s:TextInput id="myID" />
</s:HGroup>
</s:HGroup>
</s:VGroup>
</s:Application>
I'm having the hardest time finding a way to simply add rounded tabs to a TabNavigator control.
I have seen examples which seem to be really simple but they don't seem to work in Flex 4.5. Here is some sample code:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Style source="style.css"/>
<mx:TabNavigator x="93" y="90" width="571" height="293" tabStyleName="tabstyle">
<s:NavigatorContent width="100%" height="100%" label="Tab 1">
</s:NavigatorContent>
</mx:TabNavigator>
</s:Application>
and the css:
/* CSS file */
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
.tabstyle
{
corner-radius: 10;
}
I have also tried cornerRadius: 10;
Any ideas why this does not work? Any easy to follow solution (I'm a beginner).
Thanks.
You could create a skin for your app/tab navigator, use the 'create copy of' option in Flash Builder, and in the Rect section, set the radiusX, radiusY values. Then use that skin for the component
This is the best and easiest workaround I know for this problem. It seems Adobe never solved this bug.
<s:VGroup width="100%" height="100%" gap="0" >
<s:Group width="100%">
<s:TabBar left="4" dataProvider="{tabNav}" cornerRadius="4" />
</s:Group>
<s:BorderContainer width="100%" height="100%" cornerRadius="4">
<mx:ViewStack id="tabNav" paddingBottom="10" width="100%" height="100%" >
<s:NavigatorContent label="Form" width="100%" height="100%">
...
</s:NavigatorContent>
<mx:Canvas id="treeNode" label="TreeNodeComponent" width="100%" height="100%">
...
</mx:Canvas>
<mx:Canvas id="melding" label="Melding" width="100%" height="100%" visible="{authorisation.moduleHasUserAutorization('melding')}" includeInLayout="{melding.visible}">
...
</mx:Canvas>
</mx:ViewStack>
</s:BorderContainer>
</s:VGroup>
It's the equivalent of this but with rounded corners in the tabs (and body):
<mx:TabNavigator id="tabNav" paddingBottom="10" width="100%" height="100%" >
<s:NavigatorContent label="Form" width="100%" height="100%">
...
</s:NavigatorContent>
<mx:Canvas id="treeNode" label="TreeNodeComponent" width="100%" height="100%">
...
</mx:Canvas>
<mx:Canvas id="melding" label="Melding" width="100%" height="100%" visible="{authorisation.moduleHasUserAutorization('melding')}" includeInLayout="{melding.visible}">
...
</mx:Canvas>
</mx:TabNavigator>
Try this!
<mx:TabNavigator id="tabNavigator" tabOffset="20" cornerRadius="10" height="100%" width="100%">
This is the sample code you can copy and run
<s:NavigatorContent id="search" label="Search" width="100%" height="100%" fontWeight="bold"
>
<s:layout>
<s:VerticalLayout horizontalAlign="center"
paddingTop="5" paddingLeft="5"
paddingRight="5" paddingBottom="5" />
</s:layout>
<s:Label text="Search Panel" />
<s:HGroup >
<s:TextInput id="Searchtxt" width="200" />
<mx:Button label="search" click="Searchtxt.text=''" />
</s:HGroup>
</s:NavigatorContent>
<s:NavigatorContent id="custInfo" label="Customer Info" backgroundColor="0xDCDCDC"
width="100%" height="100%" fontWeight="bold" >
<s:layout>
<s:VerticalLayout horizontalAlign="center"
paddingTop="5" paddingLeft="5"
paddingRight="5" paddingBottom="5" />
</s:layout>
<s:Label text="Customer Info" />
<s:HGroup>
<s:Label text="Email Address"/>
<s:TextInput id="email" width="200"/>
<s:Button label="Submit" click="email.text='';" />
</s:HGroup>
</s:NavigatorContent>
<s:NavigatorContent id="accountInfo" label="Account Info" backgroundColor="0xDCDCDC" width="100%" height="100%" fontWeight="bold" >
<s:layout>
<s:VerticalLayout horizontalAlign="center"
paddingTop="5" paddingLeft="5"
paddingRight="5" paddingBottom="5" />
</s:layout>
<s:Label text="Account Info" />
<s:HGroup>
<s:Button label="Purchases" />
<s:Button label="Sales" />
<s:Button label="Reports" />
</s:HGroup>
</s:NavigatorContent>
</mx:ViewStack>
Is there a way to align an image to the rightmost of HGroup, which is setted to 100% width ?
here is my code, but it aligning the image "imageZoom" just after the object before it :
<s:VGroup id="masterVGroup" width="100%">
<s:HGroup id="masterHGroup" gap="3" width="100%" verticalAlign="middle">
<s:SpriteVisualElement id="colorBox" width="12" height="6""/>
<s:Label id="labelDisplay" text="delete"/>
<s:Image id="imageZoom"
right="2"
horizontalAlign="right"
source="{iconZOOM}"/>
</s:HGroup>
</s:VGroup>
<s:VGroup id="masterVGroup" width="100%">
<s:HGroup id="masterHGroup" gap="3" width="100%" verticalAlign="middle" horizontalAlign="right">
<s:SpriteVisualElement id="colorBox" width="12" height="6""/>
<s:Label id="labelDisplay" text="delete"/>
<s:Image id="imageZoom"
right="2"
horizontalAlign="right"
source="{iconZOOM}"/>
</s:HGroup>
</s:VGroup>
I think it should work :)
In a case you want to have SpriteVisualElement and Label instances on the same places you can use spacer:
<s:VGroup id="masterVGroup" width="100%">
<s:HGroup id="masterHGroup" gap="3" width="100%" verticalAlign="middle">
<s:SpriteVisualElement id="colorBox" width="12" height="6""/>
<s:Label id="labelDisplay" text="delete"/>
<mx:Spacer width="100%"/>
<s:Image id="imageZoom"
right="2"
horizontalAlign="right"
source="{iconZOOM}"/>
</s:HGroup>
</s:VGroup>
No matter what value I put in the horizontalCenter property of the "Browse" button, it just follows the horizontalAlign property of the VGroup. Why is that ?
Thanks
<s:Group width="100%" height="100%" left="0" right="0" top="0" bottom="0">
<s:Panel id="mainPanel" title="File uploader" width="75%" height="75%" horizontalCenter="0" verticalCenter="0">
<s:controlBarContent> <s:Label text="foo"/> </s:controlBarContent>
<mx:HDividedBox width="100%" height="100%">
<s:VGroup width="25%" height="100%" paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10">
<s:TextArea width="100%" height="100%" />
<s:Button label="Browse" horizontalCenter="30"/>
</s:VGroup>
<s:TextArea width="100%" height="100%" />
</mx:HDividedBox>
</s:Panel>
</s:Group>
The VGroup in Flex 4 uses spark.layouts.VerticalLayout which doesn't take into account horizontalCenter/verticalCenter :/. I don't like that myself.
But since your VGroup's child TextArea is 100% width/height, you can use the VerticalLayout/VGroup horizontalAlign property: horizontalAlign="center". That works:
<s:Group width="100%" height="100%" left="0" right="0" top="0" bottom="0">
<s:Panel id="mainPanel" title="File uploader" width="75%" height="75%" horizontalCenter="0" verticalCenter="0">
<s:controlBarContent>
<s:Label text="foo"/>
</s:controlBarContent>
<mx:HDividedBox width="100%" height="100%">
<s:VGroup width="25%" height="100%" paddingLeft="10" horizontalAlign="center" paddingRight="10" paddingTop="10" paddingBottom="10">
<s:TextArea width="100%" height="100%" />
<s:Button label="Browse" horizontalCenter="30"/>
</s:VGroup>
<s:TextArea width="100%" height="100%" />
</mx:HDividedBox>
</s:Panel>
</s:Group>