2
我有一個帶有標籤的BorderContainer。我需要這個標籤在容器內居中。 BorderContainer沒有佈局(我猜它是默認的,basicLayout ...)。Flex/as3:如果我設置了BorderContainer的BorderWeight,包含的標籤被移動了......爲什麼?
我的代碼:
使用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屬性,文本將被移動!!!!!
謝謝先進。
你爲什麼要動態地添加這個文本?這是否有很好的理由? – 2011-05-22 14:13:26