2

ラベルが入った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プロパティを設定すると、テキストがシフトします!!!!!

よろしくお願いします。

4

1 に答える 1

1

したがって、「シフト」の意味がわかりません。あなたのコードで問題を再現できませんでした...あなたのコードは不完全ですが。たとえば、countdownTextまたはとは何ですか?bordercontainer1_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>
于 2011-05-22T14:36:18.910 に答える