Is it there a property to arrange menu items horizontally AndEngine? The default layout is vertical, do you know a way to set it horizontal?
Asked
Active
Viewed 228 times
0
-
I did it before, check [mine](https://github.com/yhuiyang/AndEngine/commit/1d28d00da8c4ca17837da024682b3eaa4eb451e7). – 正宗白布鞋 Jun 01 '14 at 02:48
2 Answers
1
There isn't a built it functionality that would arrange menu items horizontally, but check the MenuSceneAnimator
class, especially getMenuItemX
and getMenuItemY
methods. It should be pretty easy to implement your own positioning that will suit your needs.

MartinTeeVarga
- 10,478
- 12
- 61
- 98
-
thanks, that's what I needed to know, will try to make a function that "horizontalizes" the layout of any and post it here. – Lucas Massuh May 28 '14 at 15:22
0
This is the solution I came up with, I know it can be optimized, but it works.
/**
* 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;
}

Lucas Massuh
- 221
- 2
- 9
-
Instead of using a static method to fix the layout later, create your own Animator class and override the placement methods. It would me much cleaner. – MartinTeeVarga May 29 '14 at 01:42