我正在开发一个bb应用程序,我想要将按钮居中。我没有使用自定义字段管理器。 以下是我的一些代码:
ButtonField button;
button=new ButtonField( "Go!" );
add(button);
我希望此按钮在屏幕上居中。需要帮忙。感谢
我试过保罗......它不起作用......这是我的主屏幕代码:
class Vfmdemo extends UiApplication {
// main method
public static void main(String[] args) {
Vfmdemo theApp = new Vfmdemo();
UiApplication.getUiApplication().pushScreen(new VFMScreen());
theApp.enterEventDispatcher();
}
}
// VFM
class VFMScreen extends MainScreen {
public VFMScreen(){
// create a manager and allow scrolling when lots of fields are added
VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);
// add a label
vfm.add(new LabelField("VerticalFieldManager..."));
// add another label
vfm.add(new LabelField("default horizontal alignment is left"));
// add another label that takes up full screen width
vfm.add(new LabelField("using all width & long label...",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH));
// add another label that takes centered horizontally
vfm.add(new LabelField("horizontally centered...",
Field.FIELD_HCENTER));
vfm.add(new ButtonField("Go!!",Field.FIELD_HCENTER));
// add vfm to screen
add(vfm);
}
答案 0 :(得分:1)
你需要使用这样的一对经理:
//使用管理员在屏幕上居中
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_HEIGHT);
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_WIDTH | FIELD_VCENTER);
vfm.add(new ButtonField("Go!", FIELD_HCENTER));
hfm.add(vfm);
add(hfm);