是否有可以水平安排菜单项AndEngine的属性? 默认布局是垂直的,你知道一种将它设置为水平的方法吗?
答案 0 :(得分:1)
没有内置的功能可以水平排列菜单项,但检查MenuSceneAnimator
类,尤其是getMenuItemX
和getMenuItemY
方法。实现适合您需求的定位应该非常容易。
答案 1 :(得分:0)
这是我提出的解决方案,我知道它可以进行优化,但它确实有效。
/**
* Sets menu items layout to horizontal
* @author Lucas Massuh
* @version 1.0
* @since 2015-05-28
* @return returns the "horizontalised" menu, just in case.
* @param menu This should be the menu scene containing all the Menu Items to be set horizontal
* @param padding This is the horizontal padding between each Menu Item
*/ private static MenuScene setMenuLayoutToHorizontal(MenuScene menu, int padding){
if (menu.getChildCount()<=1) return menu;
// Starts at 1 since child[0] position won't be changed
for(int i=1; i<menu.getChildCount();i++){
menu.getChildByIndex(i).setPosition(
//it can be optimized by pre-calculating item's width if they are all equal
menu.getChildByIndex(i-1).getX()+menu.getChildByIndex(i).getWidth()+padding,
menu.getChildByIndex(0).getY());
}
return menu;
}