0

我正在开发一个黑莓项目,为此我需要创建网格布局。我正在研究“黑莓 java sdk”。

我正在使用此代码

 public class GridScreen extends UiApplication {
// main method
public static void main(String[] args) {

GridScreen theApp = new GridScreen();
UiApplication.getUiApplication().pushScreen(new GFMScreen());
theApp.enterEventDispatcher();

}

}

// VFM
class GFMScreen extends MainScreen {

public GFMScreen() {

// this doesnt do anything for VCENTER!!
//super(Field.USE_ALL_HEIGHT);

// create a grid field manager, with 2 cols and 0 style param for super class
// style of Manager.FIELD_VCENTER | Field.USE_ALL_HEIGHT doesnt do a thing!
int columns = 2;
final GridFieldManager gfm = new GridFieldManager(columns, 0);

// add some items to the screen
 int size = 6;
 BitmapField[] fRay = new BitmapField[size];
 for (int i = 0; i < size; i++) {
  // create an bitmap field that's centered H + V (inside grid space)
  fRay[i] = new BitmapField(loadBitmap("images/" + (i + 1) + ".png"),
                          Field.FIELD_HCENTER | Field.FIELD_VCENTER | Field.FOCUSABLE);
   gfm.add(fRay[i]);
  }

  // set padding on top/bottom
 {
   // add gfm to screen - this does not center the gfm on the screen... is top aligned        no matter what!
   add(gfm);

     int gfmHeight = 48 * (size / columns);
  int borderHeight = (Display.getHeight() - gfmHeight) / 2;
   gfm.setBorder(BorderFactory.createSimpleBorder(
     new XYEdges(borderHeight, 0, borderHeight, 0),
     Border.STYLE_TRANSPARENT));

   System.out.println("border=" + borderHeight);
   System.out.println("display=" + Display.getHeight());
   System.out.println("gfm=" + gfmHeight);

  }

}

 /** @param res eg "images/icon.png" */
 public static Bitmap loadBitmap(String res) {
  EncodedImage img = EncodedImage.getEncodedImageResource(res);
  return img.getBitmap();
 }

}// end class

这段代码有什么问题?是否有在 BlackBerry 中创建网格布局的最佳方法。在上面的代码错误是“Display.getHeight() 没有定义”。

4

1 回答 1

0

希望这段代码有帮助:

Bitmap[] images = new Bitmap[6];
for ((int i = 0; i < 6; i++) {
   string filename = "images/" + String.valueOf(i + 1) + ".png"; 
   images[i] = Bitmap.getBitmapResource(filename);  
   }               
}
于 2012-12-27T07:44:04.200 回答