Flex/as3:如果我设置 BorderContainer 的 BorderWeight,则包含的标签会移动...为什么?

发布于 2024-11-09 03:36:51 字数 1707 浏览 0 评论 0原文

我有一个 BorderContainer,里面有一个标签。我需要这个标签位于容器内的中心。 BorderContainer 没有布局(我猜它得到的是默认布局,basicLayout...)。

我的代码:

BorderContainer的定义:

<s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               creationComplete="bordercontainer1_creationCompleteHandler(event)"
                addedToStage="bordercontainer1_addedToStageHandler(event)"
               cornerRadius="200" borderWeight="20"  >

当我的BorderContainer完成时,我动态加载标签:

protected function bordercontainer1_creationCompleteHandler(event:FlexEvent):void
        {
            // TODO Auto-generated method stub
            var countdownText:Label = new Label();
                countdownText.width = this.width * 0.5;
                //countdownText.height = this.height * 0.5;
                countdownText.text =String( countdownDuration );
                    countdownText.setStyle("fontSize","200");
                    countdownText.setStyle("fontFamily", "Arial");
                    countdownText.setStyle("color","#FF0000");
                    countdownText.setStyle("fontWeight", "bold" );
                    countdownText.setStyle("textAlign", "center");                  
                this.addElement(countdownText);
                //trace("width border:", this.width, ", text width:", countdownText.width);
                countdownText.x = (this.width-countdownText.width)/2;
                countdownText.y = (this.width-countdownText.width)/2;

        }

使用此代码,标签的文本在容器中居中,但如果我设置BorderWeight属性,文本就会移动!

提前致谢。

I have a BorderContainer with a Label inside. I need this Label to be centered inside the container. BorderContainer has no layout (I guess it getst the default one, basicLayout...).

My code:

BorderContainer's definition:

<s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               creationComplete="bordercontainer1_creationCompleteHandler(event)"
                addedToStage="bordercontainer1_addedToStageHandler(event)"
               cornerRadius="200" borderWeight="20"  >

When my BorderContainer is completed, I load dynamically the Label:

protected function bordercontainer1_creationCompleteHandler(event:FlexEvent):void
        {
            // TODO Auto-generated method stub
            var countdownText:Label = new Label();
                countdownText.width = this.width * 0.5;
                //countdownText.height = this.height * 0.5;
                countdownText.text =String( countdownDuration );
                    countdownText.setStyle("fontSize","200");
                    countdownText.setStyle("fontFamily", "Arial");
                    countdownText.setStyle("color","#FF0000");
                    countdownText.setStyle("fontWeight", "bold" );
                    countdownText.setStyle("textAlign", "center");                  
                this.addElement(countdownText);
                //trace("width border:", this.width, ", text width:", countdownText.width);
                countdownText.x = (this.width-countdownText.width)/2;
                countdownText.y = (this.width-countdownText.width)/2;

        }

With this code the Label's text is centered in the container, but if I set the BorderWeight property, the text is shifted!!!!!

Thanks in advanced.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

榆西 2024-11-16 03:36:51

所以,我不确定你所说的“转移”是什么意思。我无法用您的代码重现问题...尽管您的代码不完整。例如,countdownTextbordercontainer1_addedToStageHandler 是什么?

如何避免动态代码并仅使用简单的数据绑定?

<fx:Declarations>
    <fx:Number id="countdownDuration">5.123</fx:Number>
</fx:Declarations>

<s:BorderContainer cornerRadius="200" borderWeight="20" width="100%" height="100%">

    <mx:Label width="50%" text="{countdownDuration}"
             fontSize="200" fontFamily="Arial" color="#FF0000"
             fontWeight="bold" textAlign="center"
             verticalCenter="0" horizontalCenter="0" />

</s:BorderContainer>

So, I am not sure what you mean by "shifted". I was not able to reproduce the problem with your code... though your code is incomplete. What is countdownText or bordercontainer1_addedToStageHandler, for instance?

How about avoiding the dynamic code and just use a simple data binding?

<fx:Declarations>
    <fx:Number id="countdownDuration">5.123</fx:Number>
</fx:Declarations>

<s:BorderContainer cornerRadius="200" borderWeight="20" width="100%" height="100%">

    <mx:Label width="50%" text="{countdownDuration}"
             fontSize="200" fontFamily="Arial" color="#FF0000"
             fontWeight="bold" textAlign="center"
             verticalCenter="0" horizontalCenter="0" />

</s:BorderContainer>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文