我使用以下代码向按钮添加图像。然而,我得到了一些按钮的窗口视图!!我应该添加什么来使它们适合于视图窗口?
加:我希望他们在中心,垂直和水平。假设我有15个按钮,每行3个。在屏幕中央??
Thanks in advance
public class BitmapButtonField extends ButtonField {
private Bitmap bitmap;
private Bitmap bitmapHighlight;
private boolean highlighted = false;
public BitmapButtonField(Bitmap bitmap, Bitmap bitmapHighlight) {
this(bitmap, bitmapHighlight, ButtonField.CONSUME_CLICK|ButtonField.FIELD_HCENTER|ButtonField.FIELD_VCENTER);
}
public BitmapButtonField(Bitmap bitmap, Bitmap bitmapHighlight, long style) {
super(style);
this.bitmap = bitmap;
this.bitmapHighlight = bitmapHighlight;
}
protected void layout(int width, int height) {
setExtent(getPreferredWidth(), getPreferredHeight());
}
public int getPreferredWidth() {
return bitmap.getWidth();
}
public int getPreferredHeight() {
return bitmap.getHeight();
}
protected void paint(Graphics graphics) {
super.paint(graphics);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Bitmap b = bitmap;
if (highlighted)
b = bitmapHighlight;
graphics.drawBitmap(0, 0, width, height, b, 0, 0);
}
}
您的字段没有任何问题。最有可能的是,你正在使用HorizontalFieldManager
,它具有无限的宽度,并将字段置于屏幕边界之外。您可以使用FlowFieldManager
更改此行为。