如何使标题图标在 Flex 3 面板中居中?

发布于 2024-11-10 14:04:07 字数 1262 浏览 5 评论 0原文

如何使标题图标在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别把无礼当个性 2024-11-17 14:04:07

扩展组件并重写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();
        }

    }
}

mx_internal 是 Fl​​ex 团队不想记录的所有内容生效(或失效)的地方。

Extend the component and override the layoutChrome method to reposition the titleIcon.

Roughly something like this:

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);
            }
 }

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:

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();
        }

    }
}

mx_internal is where all the stuff the Flex Team doesn't want to document goes to live (or die).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文