我有一个带有标签的 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 属性,则文本会移动!!!!!!
先谢谢了。