0

私はブラックベリー プロジェクトに取り組んでおり、そのためにグリッド レイアウトを作成する必要があります。「Blackberry 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 に答える