2010-11-02 46 views
3

我正在嘗試使用JDE4.2.1開發我的第一個黑莓手機屏幕。
我想創建看起來像這樣的佈局:BlackBerry佈局管理器問題,虛擬大小

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

到目前爲止,我已經成功地實現了這一佈局水平和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)並嘗試居中時,它最終會溢出右側的屏幕物理大小。 Nevermind標題或頁腳中的字符數。 由於某種原因,似乎管理器虛擬大小是屏幕大小的兩倍。

是否有反正我可以限制bodyContentMgr的虛擬尺寸爲屏幕物理尺寸?

結果:

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

對於做得很好的ASCII藝術+1 :) – 2010-11-02 16:15:39

+0

你會學會討厭黑莓UI設計。您是否嘗試過創建垂直字段管理器的匿名實例,並使用getPreferedWidth()或sublayout()強制寬度? – Nicholas 2010-11-10 07:18:40

回答

1

的VerticalFieldManager有固定JDE5.0一些顯著錯誤,所以你可以嘗試佈局與5.0模擬器,看看問題是否會消失。如果是這樣,那麼這是一個解決bug的問題,而不是佈局的一些基本問題。

+0

現貨。不幸的是,我的要求是針對JDE4.2.1我想我可以找到軟件版本並且如果小於5.0就對齊。 – emt14 2010-11-03 10:19:04