Java BlackBerry布局管理器问题,虚拟大小
我正在尝试用JDE4.2.1为黑莓开发我的第一个屏幕。Java BlackBerry布局管理器问题,虚拟大小,java,user-interface,blackberry,layout,screen,Java,User Interface,Blackberry,Layout,Screen,我正在尝试用JDE4.2.1为黑莓开发我的第一个屏幕。 我尝试创建的布局如下所示: --------------------------------- ! Header img ! !-------------------------------! ! I ! Title ! ! M !--------------------------! ! G ! Body Txt ! !
我尝试创建的布局如下所示: --------------------------------- ! Header img ! !-------------------------------! ! I ! Title ! ! M !--------------------------! ! G ! Body Txt ! ! ! ! ! ! Button1 Button2 ! ! !--------------------------! ! ! Footer text ! ---------------------------------
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)并尝试将其居中时,它最终会溢出右侧的屏幕物理大小。不要指定标题或页脚中的字符数。
出于某种原因,manager虚拟大小似乎是屏幕大小的两倍
我是否可以将bodyContentMgr的虚拟大小限制为屏幕物理大小
结果:
---------------------------------
! Header img !
!-------------------------------!
! I ! Title !
! M !-----------------------------------------------!
! G ! Body Txt !
! ! !
! ! Button1 Button2 !
! !-----------------------------------------------!
! ! Footer text !
--------------------------------!
---------------------------------
! 头img!
!-------------------------------!
! 我标题
! M!------------------------------------------------------------!
! GBody Txt!
! ! !
! ! 按钮1按钮2!
! !-----------------------------------------------!
! ! 页脚文字!
--------------------------------!
VerticalFieldManager在JDE5.0中修复了一些重要的错误,因此您可以使用5.0模拟器尝试布局,看看问题是否消失。如果是这样的话,那么这是一个解决bug的问题,而不是布局的一些基本问题。+1对于做得很好的ASCII艺术:)你将学会讨厌黑莓的UI设计。您是否尝试过创建垂直字段管理器的匿名实例,并使用getPreferedWidth()或sublayout()强制设置宽度。不幸的是,我的需求是针对JDE4.2.1的,我想如果小于5.0,我可以找到软件版本并正确对齐。