0
A
回答
0
從flexdeveloper.eu,設置itemAlign
到中心:
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;
}
}
}
0
相關問題
- 1. 對齊李菜單項中心
- 2. Flex 4.5,對齊表單helpcontent搞砸了
- 3. 在Flex中對齊中心
- 4. CSS對齊子菜單中心的WordPress
- 5. 中心對齊下拉菜單中的每個導航項
- 6. 如何中心對齊此菜單
- 7. CSS:將菜單對齊中心
- 8. 中心對齊Flex項目中的絕對元素
- 9. 菜單項不對齊
- 10. 右對齊菜單項
- 11. 菜單項對齊WPF
- 12. CSS菜單 - 左對齊圖像和右對齊菜單項
- 13. 中心與父母父母的下拉菜單中心對齊
- 14. 溢出菜單項文本對齊到中心
- 15. Flex:從菜單中隱藏菜單項?
- 16. 將flex與中心的特定項目對齊
- 17. QListWidget對齊項目中心
- 18. 垂直對齊的菜單項
- 19. 菜單項的actionView右對齊
- 20. 在下拉菜單中對齊中心的一個元素
- 21. 中心對齊HTML頁面中的固定頂級菜單
- 22. SwRevealview中的Menuviewcontroller滑動菜單不是在中心對齊
- 23. 中心對齊導航欄中的菜單
- 24. 引導程序中的中心對齊菜單
- 25. 表對齊中心不對齊中心
- 26. 如何對齊菜單項彈出的菜單的右下角
- 27. 在wpf中對齊菜單
- 28. 居中菜單左對齊
- 29. 中心菜單項目
- 30. 帶有對齊子菜單項的全寬子菜單
MX組件是Flex 3個的組件,並且您在此找到教程可能提供正確的解決方案。 Flex 4中的新功能是Spark組件。 – JeffryHouser