【发布时间】:2011-05-03 20:32:37
【问题描述】:
我正在尝试使用 JDE4.2.1 为 Blackberry 开发我的第一个屏幕。
我尝试创建的布局如下所示:
到目前为止,我已经设法通过结合 Horizontal 和 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 的虚拟大小限制为屏幕物理大小吗?
结果:
--------------------------------- !标题图片! !-------------------------------! !一世 !标题 ! !米!----------------------------------------------! ! G !正文文本! ! ! ! ! !按钮 1 按钮 2 ! ! !------------------------------------------------------------! ! !页脚文字! --------------------------------!【问题讨论】:
-
+1 表示精美的 ASCII 艺术 :)
-
你将学会讨厌黑莓 UI 设计。您是否尝试过创建垂直字段管理器的匿名实例并使用 getPreferedWidth() 或 sublayout() 强制设置宽度?
标签: java user-interface blackberry layout screen