apache-flex - flex 4 组中的中心元素

标签 apache-flex actionscript flex4

我正在使用 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>

最佳答案

其他人理解为什么会发生这种情况可能会有所帮助,因为这是一个常见问题。

当您使用Horizo​​ntalLayoutVerticalLayout时,您在“布局对象”上设置的某些属性不会被使用。发生这种情况是因为这些属性在垂直/水平布局中实际上不起作用或没有意义。

垂直/水平布局忽略的布局属性:

  • xy 坐标
  • horizo​​ntalCenterverticalCenter
  • 顶部底部约束

上述属性适用于默认的 BasicLayout 类。

正如 @Mahesh Parate 的回答所示,垂直/水平布局确实允许使用 horizo​​ntalAlignverticalAlign 属性将内容居中。

关于apache-flex - flex 4 组中的中心元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13476917/

相关文章:

actionscript-3 - Flex 4.6 中心图像

apache-flex - 视频全屏显示

flash - AS3 : defining hit area

actionscript - Flash HTTP 流式传输 - 多个文件

apache-flex - Adobe Flash Builder(flex4): addChild() is not available in this class.

flash - 大型 Flash 项目的构建/部署过程?

java - 需要了解 WAR 描述符和结构 - WAR 中的 Flex 项目

flash - Actionscript 3 mouseover passthrough(忽略鼠标事件)

apache-flex - Flex 4.5 - 如何检测屏幕尺寸以使图像在移动设备上居中?

apache-flex - Actionscript 或 Flex 库哪个是正确的术语?