【问题标题】:flex 4 center element in a groupflex 4 组中的中心元素
【发布时间】:2012-11-20 15:51:15
【问题描述】:

我正在使用 flex 4 GUI 进行简单对齐,但不知道为什么。

我有 button1、button2 和一个文本字段。我想将它们水平对齐,并将文本垂直居中。 对于以下代码,我看到以下输出。

_______   ______
|bt1   | |bt2   |   text1
|______| |______|     

我的问题是; 1)为什么我在 btn 1 verticalCenter="10" 和 btn2 verticalCenter="-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>

【问题讨论】:

    标签: apache-flex actionscript flex4


    【解决方案1】:

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

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

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

    • xy 坐标
    • horizontalCenterverticalCenter
    • top, bottom, left, right 约束

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

    正如@Mahesh Parate 的回答所指出的,垂直/水平布局确实允许使用horizontalAlignverticalAlign 属性使内容居中。

    【讨论】:

      【解决方案2】:

      以下代码可能对您有所帮助:- 在 Horizo​​ntalLayout 中添加 verticalAlign="middle" 这将解决您的问题。

      <?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:Script>
              <![CDATA[
      
                  protected function onClickHandler(event:MouseEvent):void
                  {
                      // TODO Auto-generated method stub
      
                  }
      
              ]]>
          </fx:Script>
          <s:Group minWidth="100" >
              <s:layout>
                  <s:HorizontalLayout verticalAlign="middle"/>
              </s:layout>
              <s:Button label="myButton" click="onClickHandler(event)" horizontalCenter="0"
                        verticalCenter="10"/>
              <s:Button label="myButton" click="onClickHandler(event)" verticalCenter="-10"/>
              <s:Group verticalCenter="0" horizontalCenter="0">
                  <s:Label text="hello" color="#FFFF" verticalCenter="0"
                           textAlign="center" />
              </s:Group>
      
          </s:Group>
      </s:Application>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-07-18
        • 2017-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-20
        相关资源
        最近更新 更多