views:

173

answers:

2

What I want to achieve is to have a custom popup screen with specified width and height. On that screen I add two buttons which stay in one row and align center horizontally.

public class CustomPopupScreen extends PopupScreen {

ButtonField minimizeBf;
ButtonField cancelBf;
HorizontalFieldManager hfm;

public CustomPopupScreen() {
    super(new VerticalFieldManager());
    minimizeBf = new ButtonField("Minimize", FIELD_HCENTER|Field.USE_ALL_WIDTH);
    cancelBf = new ButtonField("Cancel", FIELD_HCENTER|Field.USE_ALL_WIDTH);
    hfm = new HorizontalFieldManager(FIELD_HCENTER|Field.USE_ALL_WIDTH);
    hfm.add(minimizeBf);
    hfm.add(cancelBf);
    add(hfm);
    //add(minimizeBf);
    //add(cancelBf);
}

protected void sublayout(int width, int height) {
    // TODO Auto-generated method stub
    int xPos = 0;
    int yPos = 0;
    int sideMargin = 30;
    int screenWidth = width - (2 * sideMargin);
    int screenHeight = 100;
    layoutDelegate(screenWidth, screenHeight);
    //setPositionDelegate(0, 0);
    super.sublayout(screenWidth, screenHeight);
    setExtent(screenWidth, screenHeight);
    xPos = (width - screenWidth) / 2;
    yPos = (height - screenHeight) / 2;
    setPosition(xPos, yPos);
    // layout(screenWidth, screenHeight);
}

}

If I add those buttons to the screen, then it will align center horizontally, but the buttons appear on different row, while I want it to appear in the same row.

Can somebody tell me where have I code wrong ?

A: 

Try removing the USE_ALL_WIDTH flag from your HorizontalFieldManager allocation. That should do the trick.

Fostah
Unfortunately it doesn't.I think I should put something in the sublayout method so the managers within this screen will align accordingly, but I just don't know what :((.Thanks for your help.
Ari R. Fikri
A: 

Try putting a couple of vertical field managers, each taking half the available width, inside the horizontal manager. then add one button to each of the vertical managers.

Jorge
Thanks for your answer.I assume if I want to create the third button then I must add a vertical manager for it too, right ?This might work, but what I want to achieve here is, how should I add something on sublayout method, so horizontalManager can do it's job on a custom popup screen.
Ari R. Fikri