Layout 图像数组
我正在从事一个黑莓项目,为此我需要创建网格布局。我正在开发“Blackberry java sdk” 我正在使用这个代码Layout 图像数组,layout,blackberry,user-interface,java-me,Layout,Blackberry,User Interface,Java Me,我正在从事一个黑莓项目,为此我需要创建网格布局。我正在开发“Blackberry java sdk” 我正在使用这个代码 public class GridScreen extends UiApplication { // main method public static void main(String[] args) { GridScreen theApp = new GridScreen(); UiApplication.getUiApplication().pushScreen(n
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
公共类GridScreen扩展UIC应用程序{
//主要方法
公共静态void main(字符串[]args){
GridScreen theApp=新建GridScreen();
UiApplication.getUiApplication().pushScreen(新的GFMScreen());
theApp.enterEventDispatcher();
}
}
//VFM
类GFMScreen扩展了主屏幕{
公共GFMScreen(){
//这对VCENTER没有任何作用!!
//超级(字段。使用所有高度);
//创建一个网格字段管理器,为super类创建2个col和0样式参数
//经理的风格。FIELD_VCENTER | FIELD.USE_所有高度都没有用!
int列=2;
最终GridFieldManager gfm=新的GridFieldManager(列,0);
//在屏幕上添加一些项目
int size=6;
BitmapField[]fRay=新的BitmapField[大小];
对于(int i=0;i
这个代码有什么问题?
在BlackBerry中是否有创建网格布局的最佳方法。
在上面的代码中,错误是“Display.getHeight()未定义”。希望此代码有助于:
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);
}
}
Bitmap[]图像=新位图[6];
对于((int i=0;i<6;i++){
string filename=“images/”+string.valueOf(i+1)+“.png”;
images[i]=Bitmap.getBitmapResource(文件名);
}
}
发布code
时,请使用代码块。没关系,我们第一次都犯了错误(实际上都是-jonSkeet)@MukulGoel-thanx。我当然记得。你能发布所有相关的代码吗?我假设该语句处于循环中。另外,你在上面的语句中得到了什么错误?如果没有错误,还有什么意外的输出?@MukulGoel-我发布了所有相关的代码。。你必须向我们展示你的loadBitmap()
方法有效,或者我们帮不了你什么。另外,请告诉我们上面的代码出了什么问题?是否引发了异常?请具体说明。另外,记住接受和/或向上投票对你有帮助的答案(通过选中最佳答案旁边的“V”图标接受)。谢谢。@MeNoMore-我不想存储Imagefolder中的所有图像。我想创建一个由Imagefolder中的几个选定图像组成的数组。有什么帮助吗?这是针对BlackBerry Java,而不是桌面Java。类(和路径)BlackBerry上不存在您使用的代码。决定将哪些图像添加到数组的标准是什么?@GauravSakhardande-无。我想根据自己的意愿添加图像。@MeNoMore-此错误正在生成,请查看“类型图像的方法createImage(字符串)未定义”。