我正在尝试用 JDE4.2.1 开发我的第一个黑莓屏幕。
我尝试创建的布局如下所示:
--------------------------------- ! 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);
}
}
问题是,当我将屏幕标题添加到 VerticalLayoutManager (bodyContentMgr) 并尝试将其居中时,它最终会溢出右侧的屏幕物理尺寸。不要介意标题或页脚中的字符数。 由于某种原因,管理器的虚拟尺寸似乎是屏幕尺寸的两倍。
无论如何我可以将 bodyContentMgr 的虚拟大小限制为屏幕物理大小吗?
结果:
--------------------------------- ! Header img ! !-------------------------------! ! I ! Title ! ! M !-----------------------------------------------! ! G ! Body Txt ! ! ! ! ! ! Button1 Button2 ! ! !-----------------------------------------------! ! ! Footer text ! --------------------------------!
最佳答案
VerticalFieldManager 在 JDE5.0 中修复了一些重大错误,因此您可以使用 5.0 模拟器尝试您的布局,看看问题是否消失。如果是这样,那就是解决错误的问题,而不是布局的一些基本问题。
关于java - BlackBerry 布局管理器问题,虚拟大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4076539/