我正在繪製Bitmap
作爲自定義字段的背景,但它不在整個字段的區域中繪製位圖。我也調整了圖像的大小,但總是會在右下方留下一些空間。這是什麼樣子:黑莓自定義字段drawBitmap不使用整個空間
下面是畫一些代碼:
public int getPreferredWidth(){
return phoneWidth;
}
public int getPreferredHeight(){
return cellHeight;
}
protected void paint(Graphics g) {
Bitmap img = Bitmap.getBitmapResource("cell_bg.png");
img.scaleInto(new Bitmap(phoneWidth, cellHeight), Bitmap.SCALE_TO_FIT);//or other scaling methods
g.drawBitmap(0, 0, phoneWidth, cellHeight, img, 0, 0);//draw background
//other steps
}
它工作正常,如果我設置Background
如下 -
Background bg = BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("cell_bg.png"),0,0,Background.REPEAT_SCALE_TO_FIT);
this.setBackground(bg);
但這種方式,背景圖片不可見onFocus
。
我在這裏做錯了什麼?
嘗試通過Display.getHeight()和Display.getWidth()方法獲取設備的高度和寬度。 –
變量'phoneWidth'被計算爲Display.getWidth(),所以這不是問題 – tipycalFlow