无法在 Blackberry 的自定义弹出屏幕上水平对齐字段

发布于 2024-09-11 01:07:54 字数 1270 浏览 2 评论 0原文

我想要实现的是拥有一个具有指定宽度和高度的自定义弹出屏幕。 在该屏幕上,我添加了两个按钮,它们位于一排并水平居中对齐。

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);
}

如果

我将这些按钮添加到屏幕上,那么它将水平居中对齐,但按钮出现在不同的行上,而我希望它出现在同一行中。

有人能告诉我我的代码哪里错了吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南巷近海 2024-09-18 01:07:56

尝试在水平管理器内放置几个垂直字段管理器,每个管理器占用可用宽度的一半。然后向每个垂直管理器添加一个按钮。

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.

别想她 2024-09-18 01:07:56

我只是想知道定制尺寸的目的。通常有一种正确的方法可以做某事,而无需手动修改布局。如果您分享您的最终目标,我们也许能够提供更好的帮助。因为看起来您几乎只想将两个按钮并排放置。要添加宽度和高度,您可以向字段管理器添加间隔符 (add(new SeparatorField())),并指定它们的宽度/高度以及管理器中您想要它们的位置。这将允许所有字段使用其默认布局模式。

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.

烟花易冷人易散 2024-09-18 01:07:56

做一个

hfm = new HorizontalFieldManager(USE_ALL_WIDTH);

我认为它可能会帮助你尝试一下。

just do one

hfm = new HorizontalFieldManager(USE_ALL_WIDTH);

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

回忆那么伤 2024-09-18 01:07:55

尝试从 Horizo​​ntalFieldManager 分配中删除 USE_ALL_WIDTH 标志。那应该可以解决问题。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文