开发者

BlackBerry layout manager issue, virtual size

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

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                !
--------------------------------!


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.

0

精彩评论

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