我需要以编程方式添加一组控件,并在它们之间添加一定数量的像素。我似乎无法找到如何在Flex文档中做到这一点。我该怎么做?Flex中的绝对定位?
1
A
回答
2
大多数容器都有一些逻辑来为你放置物品,例如垂直或水平。即如果要水平放置他们有5个像素的空间,你可以使用一个HBox中(垂直框垂直布局):
<mx:HBox horizontalGap="5">
<Component1/>
<Component2/>
<etc.../>
</mx:HBox>
或脚本:
...
var box: HBox = new HBox();
box.horizontalGap = 5;
box.addChild(new Component1());
box.addChild(new Component2());
addChild(box);
但是如果你想使用自己将它们放置X,Y坐标(即绝对定位),可以使用帆布:
<mx:Canvas>
<Component1 x="100" y="100"/>
<Component2 x="100" y="200"/>
<etc.../>
</mx:Canvas>
脚本版本:
var canvas: Canvas = new Canvas();
var component1: Component1 = new Component1();
component1.x = 100;
component1.y = 100;
canvas.addChild(component1);
var component2: Component2 = new Component2();
component2.x = 100;
component2.y = 100;
canvas.addChild(component2);
2
在具有绝对定位的容器例如画布中,可以使用x和y(或右,左,上,下)定位元素
elem.x = 100;
elem.y = 200;
canvas.addChild(elem);
0
您还可以使用Spacer在组件之间添加一些空间。
<mx:HBox>
<Component1 />
<mx:Spacer width="10" />
<Component2 />
</mx:HBox>
0
如果你的窗口可以调整大小,不建议绝对布局 - 这可能是一个好主意,用WIDTH =“100%”和高度= 100%,然后使用了minHeight/minWidth/maxWidth等等。 在你的情况下,你可以设置隔离器的最小宽度/高度(在两个组件之间),以便页面按比例缩放。
他也可以指定元素在它自己的元素中的位置。例如: –
2009-11-08 13:35:31