Apache flex Flex 4.5将菜单项居中对齐
我已经搜索过了,但是所有的图坦卡门都是Flex3的 Flex 4.5中对齐条中间的mx:MenuBar项的方法是什么Apache flex Flex 4.5将菜单项居中对齐,apache-flex,flex4,menubar,alignment,menu-items,Apache Flex,Flex4,Menubar,Alignment,Menu Items,我已经搜索过了,但是所有的图坦卡门都是Flex3的 Flex 4.5中对齐条中间的mx:MenuBar项的方法是什么 通常它们位于最左侧为什么不将菜单栏放在父容器中呢?父容器将具有100%的宽度,而菜单栏则没有。然后可以将菜单栏水平放置在该容器内。从,将itemAlign设置为居中: MX组件是Flex3组件,您在上面找到的教程可能提供了正确的解决方案。Flex4中的新功能是Spark组件。 package custom{ import flash.geom.Rectangle;
通常它们位于最左侧为什么不将菜单栏放在父容器中呢?父容器将具有100%的宽度,而菜单栏则没有。然后可以将菜单栏水平放置在该容器内。从,将itemAlign设置为居中:
MX组件是Flex3组件,您在上面找到的教程可能提供了正确的解决方案。Flex4中的新功能是Spark组件。
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;
}
}
}