为什么 HorizontalCenter 和 VerticalCenter 在 Spark (Flex 4) 中不起作用?
下面的代码将屏幕分为左右两列。然后它在每列中放置一个框并尝试将它们居中。 HorizontalCenter 和 VerticalCenter 属性被忽略:
<?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"
backgroundColor="blue">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:SkinnableContainer id="mainContentArea"
top="100" bottom="100"
backgroundColor="red">
<s:layout>
<s:ConstraintLayout>
<s:constraintColumns>
<s:ConstraintColumn id="col1" width="{width/2}" />
<s:ConstraintColumn id="col2" width="{width/2}" />
</s:constraintColumns>
</s:ConstraintLayout>
</s:layout>
<s:BorderContainer id="greenContainer"
backgroundColor="green"
width="400" height="300"
horizontalCenter="col1:0"
verticalCenter="0">
</s:BorderContainer>
<s:BorderContainer id="yellowContainer"
backgroundColor="yellow"
width="200" height="150"
horizontalCenter="col2:0"
verticalCenter="0">
</s:BorderContainer>
</s:SkinnableContainer>
</s:Application>
Here's code that splits the screen into two columns, left and right. Then it puts a box in each column and attempts to center them. The horizontalCenter and verticalCenter properties are ignored:
<?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"
backgroundColor="blue">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:SkinnableContainer id="mainContentArea"
top="100" bottom="100"
backgroundColor="red">
<s:layout>
<s:ConstraintLayout>
<s:constraintColumns>
<s:ConstraintColumn id="col1" width="{width/2}" />
<s:ConstraintColumn id="col2" width="{width/2}" />
</s:constraintColumns>
</s:ConstraintLayout>
</s:layout>
<s:BorderContainer id="greenContainer"
backgroundColor="green"
width="400" height="300"
horizontalCenter="col1:0"
verticalCenter="0">
</s:BorderContainer>
<s:BorderContainer id="yellowContainer"
backgroundColor="yellow"
width="200" height="150"
horizontalCenter="col2:0"
verticalCenter="0">
</s:BorderContainer>
</s:SkinnableContainer>
</s:Application>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自文档:
因此,
horizontalCenter
和verticalCenter
不在支持的约束列表中。我建议您使用以下代码:
From the documentation:
So
horizontalCenter
andverticalCenter
are not in the list of supported constraints.I recommend you to use the following code: