黑莓布局管理器问题,虚拟大小

3
我正在尝试使用JDE4.2.1为Blackberry开发我的第一个屏幕。
我想要创建的布局如下所示:
---------------------------------
!   Header img                  !
!-------------------------------!
! I  !         Title            !
! M  !--------------------------!
! G  !  Body Txt                !
!    !                          !
!    !  Button1 Button2         !
!    !--------------------------!
!    !      Footer text         !
---------------------------------

到目前为止,我已经通过Horizontal和VerticalFieldLayout的组合实现了此布局,代码如下:

class MyScreen extends MainScreen {

    RadioButtonGroup _optionGroup = new RadioButtonGroup();
    Manager _sideBarHzMgr = new HorizontalFieldManager();
    Manager _bodyContentMgr = new VerticalFieldManager();

    public MyScreen(String label) {
        super();
        doHeader(label);
        doBody();
        doFooter();
    }

    void doHeader(String label) {
        setTitle(new LabelField("Application v1.0.1", LabelField.ELLIPSIS));

        Bitmap headerImg = Bitmap.getBitmapResource("header1.jpg");
        headerImg = cropBitmap(headerImg, Display.getWidth(), headerImg.getHeight());
        add(new BitmapField(headerImg));

        Bitmap sidebar = Bitmap.getBitmapResource("sidebar.jpg");
        sidebar = cropBitmap(sidebar, sidebar.getWidth(), Display.getHeight());
        BitmapField bf = new BitmapField(sidebar, BitmapField.NON_FOCUSABLE);

        _sideBarHzMgr.add(bf);

        //Add the screen label to the main body layout
        RichTextField rtf = new RichTextField(label, new int[] { 0, label.length() }, new byte[] { 0 },
                new Font[] { Font.getDefault().derive(Font.BOLD) }, RichTextField.TEXT_ALIGN_HCENTER
                | RichTextField.NON_FOCUSABLE);
        _bodyContentMgr.add(rtf);


    }

    void doBody() {
                RadioButtonField rbField1 = new RadioButtonField("Option1", _optionGroup, true,
                        RadioButtonField.FIELD_LEFT);
                RadioButtonField rbField2 = new RadioButtonField("Option2", _optionGroup, false,
                        RadioButtonField.FIELD_LEFT);

                super._bodyContentMgr.add(rbField1);
                super._bodyContentMgr.add(rbField2);

                //Center the buttons in body content area horizontally
                HorizontalFieldManager hfm = new HorizontalFieldManager(Manager.FIELD_LEFT);
                hfm.add(_closeButton);
                hfm.add(_contButton);

                super._bodyContentMgr.add(hfm);
    }

    void doFooter() {
        _bodyContentMgr.add(new LabelField());
        _bodyContentMgr.add(new SeparatorField());
        _bodyContentMgr.add(new RichTextField("©MyCo footer 2010.", RichTextField.TEXT_ALIGN_HCENTER
                | RichTextField.NON_FOCUSABLE | RichTextField.FIELD_BOTTOM));
        //Finaly add the layout managers to the main screen
        _sideBarHzMgr.add(_bodyContentMgr);
        add(_sideBarHzMgr);
    }
}

问题是当我将屏幕标题添加到VerticalLayoutManager(bodyContentMgr)并尝试将其居中时,它最终会在右侧溢出屏幕的物理尺寸。不要关注标题或页脚中的字符数。 似乎该管理器的虚拟大小是屏幕大小的两倍,原因不明。
有没有办法限制bodyContentMgr的虚拟大小为屏幕物理大小?
结果:
---------------------------------
!   头部图像                     !
!-------------------------------!
! I  !                         标题                  !
! M  !-----------------------------------------------!
! G  !  正文文本                                    !
!    !                                               !
!    !  按钮1 按钮2                              !
!    !-----------------------------------------------!
!    !                    页脚文字                !
--------------------------------!

2
+1给漂亮的ASCII艺术品 :) - Marc Novakowski
你会学会讨厌黑莓的UI设计。你尝试过创建一个匿名实例的Vertical Field Manager并使用getPreferedWidth()或sublayout()强制设置宽度吗? - Nicholas
1个回答

1

VerticalFieldManager在JDE5.0中修复了一些重要的错误,因此您可以尝试使用5.0模拟器来布局,看看问题是否消失。如果是这样,那么就是解决错误的问题,而不是您的布局存在根本性问题。


非常准确。不幸的是,我的要求是针对JDE4.2.1版本的。我想如果低于5.0版本,我可以找出软件版本并进行正确对齐。 - emt14

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接