Blackberry应用程序中屏幕中央的对齐按钮

Blackberry应用程序中屏幕中央的对齐按钮,blackberry,Blackberry,我正在开发一个bb应用程序,我想中心按钮。我没有使用自定义字段管理器。 下面是我的一些代码: ButtonField button; button=new ButtonField( "Go!" ); add(button); 我希望这个按钮在屏幕上居中。我需要帮助。谢谢 我试过Paul…它不起作用…以下是我在主屏幕上的代码: class Vfmdemo extends UiApplication {

我正在开发一个bb应用程序,我想中心按钮。我没有使用自定义字段管理器。 下面是我的一些代码:

        ButtonField button;
        button=new ButtonField( "Go!" );
        add(button);
我希望这个按钮在屏幕上居中。我需要帮助。谢谢

我试过Paul…它不起作用…以下是我在主屏幕上的代码:

                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);

         }

您需要使用一对这样的管理器:

//使用管理器在屏幕上居中显示字段

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); 

谢谢paul..但是那根本没有显示按钮。我已经包含了我的代码。在vfm.add行上设置一个断点(new ButtonField(“Go!”,FIELD_HCENTER));并在调试模式下运行,您的代码是否运行到该行?我修改了我的代码,并使其与管理器(上面包含的代码)的按钮居中。下一个问题是,我需要为按钮创建一个侦听器。我看到的示例在使用布局管理器时不会创建侦听器…我如何实现按钮侦听器并同时使用管理器?我建议您打开一个新问题,因为这与原始问题的主题几乎没有关系。按照“如何为按钮创建侦听器”的思路,提供您迄今为止尝试过的示例。