Flex/as3:如果我设置 BorderContainer 的 BorderWeight,则包含的标签会移动...为什么?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以,我不确定你所说的“转移”是什么意思。我无法用您的代码重现问题...尽管您的代码不完整。例如,
countdownText
或bordercontainer1_addedToStageHandler
是什么?如何避免动态代码并仅使用简单的数据绑定?
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
orbordercontainer1_addedToStageHandler
, for instance?How about avoiding the dynamic code and just use a simple data binding?