我正在使用 Flex 4 GUI 进行简单的对齐,但不明白为什么。
我有按钮1、按钮2 和一个文本字段。我想将它们水平对齐,并将文本垂直居中。 对于以下代码,我看到以下输出。
_______ ______
|bt1 | |bt2 | text1
|______| |______|
我的问题是; 1)为什么我在 btn 1verticalCenter=“10”和 btn2verticalCenter=“-10”上发送的属性它们仍然对齐?我不应该看到一个在上面,一个在下面吗? 2)为什么我的text1是顶部对齐的,即使我将其设置为verticalCenter=0,我在组中或没有组中都尝试过。
谢谢大家
<?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:Group minWidth="100">
<s:layout>
<s:HorizontalLayout/>
</s:layout>
<s:Button label="myButton" click="" horizontalCenter="0"
verticalCenter="10"/>
<s:Button label="myButton" click="" verticalCenter="-10"/>
<s:Group verticalCenter="0" horizontalCenter="0">
<s:Label text="hello" color="#FFFF" verticalCenter="0"
textAlign="center" />
</s:Group>
</s:Group>
</s:Application>
最佳答案
其他人理解为什么会发生这种情况可能会有所帮助,因为这是一个常见问题。
当您使用HorizontalLayout
或VerticalLayout
时,您在“布局对象”上设置的某些属性不会被使用。发生这种情况是因为这些属性在垂直/水平布局中实际上不起作用或没有意义。
垂直/水平布局忽略的布局属性:
x
和y
坐标horizontalCenter
和verticalCenter
顶部
、底部
、左
、右
约束
上述属性适用于默认的 BasicLayout
类。
正如 @Mahesh Parate 的回答所示,垂直/水平布局确实允许使用 horizontalAlign
和 verticalAlign
属性将内容居中。
关于apache-flex - flex 4 组中的中心元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13476917/