BlackBerry 布局管理器问题,虚拟尺寸

发布于 2024-09-30 05:36:19 字数 3696 浏览 0 评论 0原文

我正在尝试使用 JDE4.2.1 开发我的第一个 Blackberry 屏幕。
我试图创建的布局如下所示:

---------------------------------
!   Header img                  !
!-------------------------------!
! I  !         Title            !
! M  !--------------------------!
! G  !  Body Txt                !
!    !                          !
!    !  Button1 Button2         !
!    !--------------------------!
!    !      Footer text         !
---------------------------------

到目前为止,我已经成功地通过 Horizo​​ntal 和 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 的虚拟尺寸限制为屏幕物理尺寸吗?

结果:

---------------------------------
!   Header img                  !
!-------------------------------!
! I  !                         Title                 !
! M  !-----------------------------------------------!
! G  !  Body Txt                                     !
!    !                                               !
!    !  Button1 Button2                              !
!    !-----------------------------------------------!
!    !                    Footer text                !
--------------------------------!

I am trying my hands at developing my first screen for Blackberry with JDE4.2.1.
The layout I am trying to create looks like this:

---------------------------------
!   Header img                  !
!-------------------------------!
! I  !         Title            !
! M  !--------------------------!
! G  !  Body Txt                !
!    !                          !
!    !  Button1 Button2         !
!    !--------------------------!
!    !      Footer text         !
---------------------------------

So far I have managed to achieved this layout with a combination of Horizontal and VerticalFieldLayout and the code look like this:

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

The problem is that when I add the Screen title to the VerticalLayoutManager (bodyContentMgr) and try to center it, it ends up overflowing the screen physical size on on the right. Nevermind the number of characters in the title or footer.
It seems that the manager virtual size is double the screen size for some reason.

Is there anyway I can limit the virtual size of the bodyContentMgr to be the screen physical size?

Result:

---------------------------------
!   Header img                  !
!-------------------------------!
! I  !                         Title                 !
! M  !-----------------------------------------------!
! G  !  Body Txt                                     !
!    !                                               !
!    !  Button1 Button2                              !
!    !-----------------------------------------------!
!    !                    Footer text                !
--------------------------------!

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

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

发布评论

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

评论(1

节枝 2024-10-07 05:36:19

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

The VerticalFieldManager had some significant bugs fixed in JDE5.0, so you might try your layout with a 5.0 simulator, to see if the problem goes away. If it does, then it's an issue of working around the bug, rather than some fundamental problem with your layout.

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