开发者

Can't align fields horizontally on custom pop up screen in Blackberry

开发者 https://www.devze.com 2023-01-09 00:38 出处:网络
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.

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 Butto开发者_如何学CnField("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 ?


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


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.


I was just wondering the purpose of having a custom size. There is often a correct way to do something without having to modify the layout manually. If you share your end goal, we may be able to help better. Since it almost appears that you want to simply make two buttons be side to side. To add width and height you can add spacers (add(new SeparatorField())) to the field managers and specify their width/height as well as where in the manager you want them. This would allow all the fields to use their default layout patterns.


just do one

hfm = new HorizontalFieldManager(USE_ALL_WIDTH);

i think it might help you just give it a try.

0

精彩评论

暂无评论...
验证码 换一张
取 消