2.九宮格布局為主題區和底部菜單區
3.将一張240*320的圖檔設定為背景圖
4.根據螢幕寬高計算出各圖示的位置,然後繪制各圖示。
具體效果,如圖所示:
核心代碼如下:
public static final String[] filenames = { "/01.png", "/02.png", "/03.png",
"/04.png", "/05.png", "/06.png" };
public static final String[] labels = { "公文推送", "通知公告", "日程安排", "通訊錄查詢",
"會議室查詢", "手機郵箱" };
public Image[] icons = new Image[9];
public void paint(Graphics g) {
int cw = this.getWidth();
int ch = this.getHeight();
try {
// paintHead(g);
this.setFullScreenMode(true);
Image img = Image.createImage("/sliderbgn.JPG");
// g.drawImage(img,0, 0, Graphics.TOP|Graphics.LEFT);
g.drawImage(img, 0, 0, Graphics.TOP
| Graphics.LEFT);
for (int i = 0; i < filenames.length; i++) {
try {
icons[i] = Image.createImage(filenames[i]);
} catch (IOException ex) {
}
}
int old_color = g.getColor();
g.setColor(0xffffff);
int startY=ch/4;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
g.drawImage(icons[i * 3 + j], j * cw / 3 + 10, startY+i * ch*3 / 10,
Graphics.TOP | Graphics.LEFT);
g.drawString(labels[i * 3 + j], j * cw / 3 + 30, startY+i * ch*3 / 10
+ icons[i].getHeight(),
Graphics.HCENTER | Graphics.TOP);
g.setColor(old_color);
paintBottom(g);
} catch (Exception ex) {
System.out.println(ex.toString());
}
}