Flex 4.5 使菜单项居中对齐

发布于 2024-12-10 01:09:34 字数 114 浏览 0 评论 0原文

我在网上搜索过,但所有这些都是针对 Flex 3 的

。Flex 4.5 中将 mx:MenuBar 项对齐在栏中间的方法是什么?

(通常它们位于最左侧)

I have searched the net, but all those tuts are for Flex 3.

What is the approcach in Flex 4.5 to align the mx:MenuBar items in middle of the bar ?

(usually they are on the far left side)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

凉世弥音 2024-12-17 01:09:34

为什么不把 MenuBar 放在父容器中呢?父容器将具有 100% 宽度,而 MenuBar 则不会。然后可以将 MenuBar 水平放置在该容器内。

Why don't you just put your MenuBar in a parent container? The parent container would have a 100% width, while the MenuBar would not. The MenuBar could then be positioned horizontally within that container.

逆光下的微笑 2024-12-17 01:09:34

来自 flexdeveloper.eu ,将 itemAlign 设置为 center

package custom{
    import flash.geom.Rectangle;

    import mx.controls.MenuBar;
    import mx.controls.menuClasses.IMenuBarItemRenderer;
    import mx.core.IFlexDisplayObject;

    public class AlignableMenuBar extends MenuBar {
        private static  const MARGIN_WIDTH:int=10;
        private var background:IFlexDisplayObject;
        public var itemAlign:String;

        public function AlignableMenuBar() {
            super();
        }

        override protected  function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
            if (this.itemAlign == "right") {
                updateDisplayListRightAlign(unscaledWidth,unscaledHeight);
            } else if (this.itemAlign == "center") {
                updateDisplayListCenterAlign(unscaledWidth,unscaledHeight);
            } else {
                updateDisplayListLeftAlign(unscaledWidth,unscaledHeight);
            }
        }

        protected function updateDisplayListLeftAlign(unscaledWidth:Number,unscaledHeight:Number):void {
            super.updateDisplayList(unscaledWidth,unscaledHeight);

            var lastX:Number=MARGIN_WIDTH;
            var lastW:Number=0;
            var len:int=menuBarItems.length;

            var clipContent:Boolean=false;
            var hideItems:Boolean=unscaledWidth == 0 || unscaledHeight == 0;

            for (var i:int=0; i < len; i++) {
                var item:IMenuBarItemRenderer=menuBarItems[i];

                item.setActualSize(item.getExplicitOrMeasuredWidth(),unscaledHeight);
                item.visible=! hideItems;

                lastX=item.x=lastX + lastW;
                lastW=item.width;

                if (! hideItems && item.getExplicitOrMeasuredHeight() > unscaledHeight || lastX + lastW > unscaledWidth) {
                    clipContent=true;
                }
            }

            if (background) {
                background.setActualSize(unscaledWidth,unscaledHeight);
                background.visible=! hideItems;
            }

            // Set a scroll rect to handle clipping.
            scrollRect=clipContent?new Rectangle(0,0,unscaledWidth,unscaledHeight):null;

        }

        protected function updateDisplayListCenterAlign(unscaledWidth:Number,unscaledHeight:Number):void {
            super.updateDisplayList(unscaledWidth,unscaledHeight);

            var len:int=menuBarItems.length;

            var totalWidth:int=0;
            for (var i:int=0; i < len; i++) {
                var tempItem:IMenuBarItemRenderer=menuBarItems[i];
                totalWidth+= tempItem.width;
            }
            var lastX:Number=(this.width - totalWidth)/2;
            var lastW:Number=0;

            var clipContent:Boolean=false;
            var hideItems:Boolean=unscaledWidth == 0 || unscaledHeight == 0;

            for (var j:int=0; j < len; j++) {
                var item:IMenuBarItemRenderer=menuBarItems[j];

                item.setActualSize(item.getExplicitOrMeasuredWidth(),unscaledHeight);
                item.visible=! hideItems;

                lastX=item.x=lastX + lastW;

                lastW=item.width;

                if (! hideItems && item.getExplicitOrMeasuredHeight() > unscaledHeight || lastX + lastW > unscaledWidth) {
                    clipContent=true;
                }
            }

            if (background) {
                background.setActualSize(unscaledWidth,unscaledHeight);
                background.visible=! hideItems;
            }

            // Set a scroll rect to handle clipping.
            scrollRect=clipContent?new Rectangle(0,0,unscaledWidth,unscaledHeight):null;


        }

        protected function updateDisplayListRightAlign(unscaledWidth:Number,unscaledHeight:Number):void {
            super.updateDisplayList(unscaledWidth,unscaledHeight);

            var len:int=menuBarItems.length;

            var totalWidth:int=0;
            for (var i:int=0; i < len; i++) {
                var tempItem:IMenuBarItemRenderer=menuBarItems[i];
                totalWidth+= tempItem.width;
            }
            var lastX:Number=this.width - totalWidth;
            var lastW:Number=0;

            var clipContent:Boolean=false;
            var hideItems:Boolean=unscaledWidth == 0 || unscaledHeight == 0;

            for (var j:int=0; j < len; j++) {
                var item:IMenuBarItemRenderer=menuBarItems[j];

                item.setActualSize(item.getExplicitOrMeasuredWidth(),unscaledHeight);
                item.visible=! hideItems;

                lastX=item.x=lastX + lastW;

                lastW=item.width;

                if (! hideItems && item.getExplicitOrMeasuredHeight() > unscaledHeight || lastX + lastW > unscaledWidth) {
                    clipContent=true;
                }
            }

            if (background) {
                background.setActualSize(unscaledWidth,unscaledHeight);
                background.visible=! hideItems;
            }

            // Set a scroll rect to handle clipping.
            scrollRect=clipContent?new Rectangle(0,0,unscaledWidth,unscaledHeight):null;
        }
    }
}

from flexdeveloper.eu, set itemAlign to center:

package custom{
    import flash.geom.Rectangle;

    import mx.controls.MenuBar;
    import mx.controls.menuClasses.IMenuBarItemRenderer;
    import mx.core.IFlexDisplayObject;

    public class AlignableMenuBar extends MenuBar {
        private static  const MARGIN_WIDTH:int=10;
        private var background:IFlexDisplayObject;
        public var itemAlign:String;

        public function AlignableMenuBar() {
            super();
        }

        override protected  function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
            if (this.itemAlign == "right") {
                updateDisplayListRightAlign(unscaledWidth,unscaledHeight);
            } else if (this.itemAlign == "center") {
                updateDisplayListCenterAlign(unscaledWidth,unscaledHeight);
            } else {
                updateDisplayListLeftAlign(unscaledWidth,unscaledHeight);
            }
        }

        protected function updateDisplayListLeftAlign(unscaledWidth:Number,unscaledHeight:Number):void {
            super.updateDisplayList(unscaledWidth,unscaledHeight);

            var lastX:Number=MARGIN_WIDTH;
            var lastW:Number=0;
            var len:int=menuBarItems.length;

            var clipContent:Boolean=false;
            var hideItems:Boolean=unscaledWidth == 0 || unscaledHeight == 0;

            for (var i:int=0; i < len; i++) {
                var item:IMenuBarItemRenderer=menuBarItems[i];

                item.setActualSize(item.getExplicitOrMeasuredWidth(),unscaledHeight);
                item.visible=! hideItems;

                lastX=item.x=lastX + lastW;
                lastW=item.width;

                if (! hideItems && item.getExplicitOrMeasuredHeight() > unscaledHeight || lastX + lastW > unscaledWidth) {
                    clipContent=true;
                }
            }

            if (background) {
                background.setActualSize(unscaledWidth,unscaledHeight);
                background.visible=! hideItems;
            }

            // Set a scroll rect to handle clipping.
            scrollRect=clipContent?new Rectangle(0,0,unscaledWidth,unscaledHeight):null;

        }

        protected function updateDisplayListCenterAlign(unscaledWidth:Number,unscaledHeight:Number):void {
            super.updateDisplayList(unscaledWidth,unscaledHeight);

            var len:int=menuBarItems.length;

            var totalWidth:int=0;
            for (var i:int=0; i < len; i++) {
                var tempItem:IMenuBarItemRenderer=menuBarItems[i];
                totalWidth+= tempItem.width;
            }
            var lastX:Number=(this.width - totalWidth)/2;
            var lastW:Number=0;

            var clipContent:Boolean=false;
            var hideItems:Boolean=unscaledWidth == 0 || unscaledHeight == 0;

            for (var j:int=0; j < len; j++) {
                var item:IMenuBarItemRenderer=menuBarItems[j];

                item.setActualSize(item.getExplicitOrMeasuredWidth(),unscaledHeight);
                item.visible=! hideItems;

                lastX=item.x=lastX + lastW;

                lastW=item.width;

                if (! hideItems && item.getExplicitOrMeasuredHeight() > unscaledHeight || lastX + lastW > unscaledWidth) {
                    clipContent=true;
                }
            }

            if (background) {
                background.setActualSize(unscaledWidth,unscaledHeight);
                background.visible=! hideItems;
            }

            // Set a scroll rect to handle clipping.
            scrollRect=clipContent?new Rectangle(0,0,unscaledWidth,unscaledHeight):null;


        }

        protected function updateDisplayListRightAlign(unscaledWidth:Number,unscaledHeight:Number):void {
            super.updateDisplayList(unscaledWidth,unscaledHeight);

            var len:int=menuBarItems.length;

            var totalWidth:int=0;
            for (var i:int=0; i < len; i++) {
                var tempItem:IMenuBarItemRenderer=menuBarItems[i];
                totalWidth+= tempItem.width;
            }
            var lastX:Number=this.width - totalWidth;
            var lastW:Number=0;

            var clipContent:Boolean=false;
            var hideItems:Boolean=unscaledWidth == 0 || unscaledHeight == 0;

            for (var j:int=0; j < len; j++) {
                var item:IMenuBarItemRenderer=menuBarItems[j];

                item.setActualSize(item.getExplicitOrMeasuredWidth(),unscaledHeight);
                item.visible=! hideItems;

                lastX=item.x=lastX + lastW;

                lastW=item.width;

                if (! hideItems && item.getExplicitOrMeasuredHeight() > unscaledHeight || lastX + lastW > unscaledWidth) {
                    clipContent=true;
                }
            }

            if (background) {
                background.setActualSize(unscaledWidth,unscaledHeight);
                background.visible=! hideItems;
            }

            // Set a scroll rect to handle clipping.
            scrollRect=clipContent?new Rectangle(0,0,unscaledWidth,unscaledHeight):null;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文