图像数组



我正在一个黑莓项目上工作,为此我需要创建网格布局。我正在开发"黑莓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

这段代码有什么问题?是否有任何最好的方法来创建网格布局的黑莓。上面的代码错误是"Display.getHeight() is not define"

希望这段代码有所帮助:

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

相关内容

  • 没有找到相关文章

最新更新