我想要实现的是具有指定宽度和高度的自定义弹出屏幕。 在该屏幕上,我添加了两个按钮,它们保持一行并水平对齐中心。无法在黑莓的自定义弹出屏幕上水平对齐字段
public class CustomPopupScreen extends PopupScreen {
ButtonField minimizeBf;
ButtonField cancelBf;
HorizontalFieldManager hfm;
public CustomPopupScreen() {
super(new VerticalFieldManager());
minimizeBf = new ButtonField("Minimize", FIELD_HCENTER|Field.USE_ALL_WIDTH);
cancelBf = new ButtonField("Cancel", FIELD_HCENTER|Field.USE_ALL_WIDTH);
hfm = new HorizontalFieldManager(FIELD_HCENTER|Field.USE_ALL_WIDTH);
hfm.add(minimizeBf);
hfm.add(cancelBf);
add(hfm);
//add(minimizeBf);
//add(cancelBf);
}
protected void sublayout(int width, int height) {
// TODO Auto-generated method stub
int xPos = 0;
int yPos = 0;
int sideMargin = 30;
int screenWidth = width - (2 * sideMargin);
int screenHeight = 100;
layoutDelegate(screenWidth, screenHeight);
//setPositionDelegate(0, 0);
super.sublayout(screenWidth, screenHeight);
setExtent(screenWidth, screenHeight);
xPos = (width - screenWidth)/2;
yPos = (height - screenHeight)/2;
setPosition(xPos, yPos);
// layout(screenWidth, screenHeight);
}
}
如果我添加这些按钮在屏幕上,那么它会水平对齐中心,但按键出现在不同的行,而我希望它出现在同一排。
有人可以告诉我我的代码错在哪里吗?
不幸的是它没有。 我想我应该把东西放在sublayout方法,所以在这个屏幕内的管理器将相应对齐,但我只是不知道:((。 感谢您的帮助。 – 2010-07-27 02:11:04