如何将垂直布局中的标签移动到flex 4.5中的任意位置?

如何解决如何将垂直布局中的标签移动到flex 4.5中的任意位置?

| 我知道这对于flex方面的专家来说非常简单,但我只是刚开始。 例如我有这个:         
<s:Label id=\"lbl2\"
         alpha=\"0.0\"
         text=\"Cute Software Engineer\"
         color=\"#ffffff\"
         fontSize=\"32\" />
我想将标签说的话移到右上方吗? 我无法将布局更改为基本/绝对布局,因为我希望标签始终始终位于屏幕的中心。经过几段动画处理后,我想将标签移到右上角。     

解决方法

        这里有两个选项(照常!)。显而易见的答案是放弃竖向布局并重构为绝对布局,使用Harry所建议的约束以及horizo​​ntalCenter和verticalCenter属性,然后无论何时何地都可以定位元素。 如果您绝对需要保留垂直布局,则另一个选择(更复杂)是创建一个包装器(像一个组)来包装您垂直布置的组件。然后从verticalLayout中删除该元素,设置其位置,然后将其添加到包装器中。 我创建了一个小测试项目来说明第二种选择。单击底部的按钮可从垂直布局中删除标签,并将其添加到位于右上角的绝对包装器中。您还可以单击“替换”按钮将元素添加回垂直组件中……希望帮助!
<?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:Script>
        <![CDATA[
            import mx.core.IVisualElement;

            protected function remove_clickHandler(event:MouseEvent):void
            {
                // remove element from relative container and store an instance of it
                var tempElement:IVisualElement = relativeContainer.removeElement(lbl2);

                // set the elements new position
                tempElement.right = 0;
                tempElement.top = 0;

                // Add element to absolute wrapper
                wrapper.addElement(tempElement);

                replace.enabled = true;
                remove.enabled = false;
            }

            protected function replace_clickHandler(event:MouseEvent):void
            {
                // remove element from absolute container and store an instance of it
                var tempElement:IVisualElement = wrapper.removeElement(lbl2);

                // Add element to relative container (at its origial position)
                relativeContainer.addElementAt(tempElement,1);

                replace.enabled = false;
                remove.enabled = true;
            }

        ]]>
    </fx:Script>

    <fx:Declarations>
    </fx:Declarations>

    <!-- ABSOLUTE WRAPPER CONTAINER (THIS COULD ALSO JUST BE THE APPLICATION ITSELF,AS LONG AS ITS LAYOUT IS SET TO BASIC) -->
    <s:Group id=\"wrapper\" width=\"800\" height=\"600\">

        <!-- FILL TO POINT OUT THAT THIS IS THE ABSOLUTE CONTAINER -->
        <s:Rect id=\"outerFill\" left=\"0\" top=\"0\"
                bottom=\"0\" right=\"0\">
            <s:fill>
                <s:SolidColor color=\"#FF0000\" alpha=\".33\"/>
            </s:fill>
        </s:Rect>

        <!-- RELATIVE CONTAINER -->
        <s:BorderContainer id=\"relativeContainer\" width=\"400\" height=\"400\"
                  verticalCenter=\"0\" horizontalCenter=\"0\">

            <s:layout>
                <s:VerticalLayout />
            </s:layout>

            <s:Label id=\"lbl1\"
                     text=\"Cute Software Engineer 1\"
                     fontSize=\"32\" />
            <s:Label id=\"lbl2\"
                     text=\"Cute Software Engineer 2\"
                     fontSize=\"32\" />
            <s:Label id=\"lbl3\"
                     text=\"Cute Software Engineer 3\"
                     fontSize=\"32\" />
        </s:BorderContainer>

        <!-- CONTROLS -->
        <s:HGroup bottom=\"5\" right=\"5\">

            <s:Button id=\"remove\" 
                      label=\"Remove Element\"
                      click=\"remove_clickHandler(event)\"/>
            <s:Button id=\"replace\" bottom=\"0\" right=\"0\"
                      label=\"Replace Element\"
                      click=\"replace_clickHandler(event)\"
                      enabled=\"false\"/>
        </s:HGroup>
    </s:Group>

</s:Application>
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?