如何使标题图标在 Flex 3 面板中居中?
如何使标题图标在 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。
有什么建议吗?谢谢。
How can I center the titleicon in a Flex 3 panel? The title is centered but the titleicon is way on the left side of the panel.
<mx:Panel
title="{myTitle}"
textAlign="center"
titleStyleName="panelTitle"
titleIcon="{myIcon}"
>
.panelTitle {
font-size: 14;
fontFamily: "Lucida Grande";
}
EDIT: I'm trying to get www.flextras.com suggestion to work. This is what I've got:
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();
}
}
}
But, I'm getting Error 1178:
1178: Attempted access of inaccessible
property titleIconObject through a
reference with static type
com.mysite.components:CenterTitleIconPanel.
Any suggestions? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
扩展组件并重写layoutChrome方法以重新定位titleIcon。
大致是这样的:
基本上,我采用组件的 unscaledWidth,减去 titleIconObject 的宽度,然后将该值减半以获得组件的 X 位置。
然后我对高度使用相同的方法。
由于 titleIconObject 是使用类似的方法定位的,因此我怀疑是否存在会影响定位的样式。
您尝试时遇到的问题是 titleIconObject 被放入自定义命名空间 mx_internal 中。这是 Flex 团队的一个黑魔法。但是,要访问该自定义命名空间中的属性,您必须导入命名空间并使用它。更新后的代码应该可以工作:
mx_internal 是 Flex 团队不想记录的所有内容生效(或失效)的地方。
Extend the component and override the layoutChrome method to reposition the titleIcon.
Roughly something like this:
I'm, basically, taking the unscaledWidth of the component, subtracting the width of the titleIconObject, and then cutting that value in half to get the X position of the component.
Then I'm using the same approach for the height.
Since the titleIconObject is positioned using a similar approach, I doubt there are styles that will affect the positioning.
The problem you're having with your attempt is that the titleIconObject is put in the custom namespace, mx_internal. This is a bit of black magic on the part of the Flex team. But, to access a property in that custom namespace, you have to import the namespace and use it. This updated code should work:
mx_internal is where all the stuff the Flex Team doesn't want to document goes to live (or die).