问题描述
|
如何将标题图标居中放置在Flex 3面板中?标题居中,但标题图标位于面板左侧。
<mx:Panel
title=\"{myTitle}\"
textAlign=\"center\"
titleStyleName=\"panelTitle\"
titleIcon=\"{myIcon}\"
>
.panelTitle {
font-size: 14;
fontFamily: \"Lucida Grande\";
}
编辑:我正在尝试获得www.flextras.com的建议。这是我所拥有的:
package com.mysite.components
{
import mx.containers.Panel;
public class CenterTitleIconPanel extends Panel
{
override protected function layoutChrome(unscaledWidth:Number,unscaledHeight:Number):void {
super.layoutChrome(unscaledWidth,unscaledHeight);
if (titleIconObject)
{
titleIconObject.move((unscaledWidth-titleIconObject.width)/2,(unscaledHeight-titleIconObject.height)/2);
}
}
public function CenterTitleIconPanel()
{
super();
}
}
}
但是,我收到错误1178:
1178:试图访问无法访问
属性titleIconObject通过
静态类型引用
com.mysite.components:CenterTitleIconPanel。
有什么建议么?谢谢。
解决方法
扩展组件并覆盖layoutChrome方法以重新定位titleIcon。
大概是这样的:
override protected function layoutChrome(unscaledWidth:Number,unscaledHeight:Number):void{
super.layoutChrone(unscaledWidth,unscaledHeight);
if (titleIconObject)
{
titleIconObject.move((unscaledWidth-titleIconObject.width)/2,(unscaledHeight-titleIconObject.height)/2);
}
}
我基本上是采用组件的unscaledWidth,减去titleIconObject的宽度,然后将该值切成两半,以获得组件的X位置。
然后,我对高度使用相同的方法。
由于titleIconObject是使用类似的方法定位的,因此我怀疑是否会有样式会影响定位。
您尝试遇到的问题是titleIconObject放在自定义名称空间mx_internal中。 Flex团队这有点不可思议。但是,要访问该自定义名称空间中的属性,您必须导入名称空间并使用它。此更新的代码应工作:
package com.mysite.components
{
import mx.containers.Panel;
import mx.core.mx_internal;
use namespace mx_internal;
public class CenterTitleIconPanel extends Panel
{
override protected function layoutChrome(unscaledWidth:Number,unscaledHeight:Number):void {
super.layoutChrome(unscaledWidth,unscaledHeight);
if (titleIconObject)
{
titleIconObject.move((unscaledWidth-titleIconObject.width)/2,(unscaledHeight-titleIconObject.height)/2);
}
}
public function CenterTitleIconPanel()
{
super();
}
}
}
Flex团队不想记录的所有内容都可以在mx_internal中使用(或终止)。