我的自定义垂直字段管理器
public class Custom_TopField extends VerticalFieldManager {
private static final int FIELD_HEIGHT = 70;
private LabelField maintitle;
private String _text;
Custom_TopField(int color, String text) {
super(Manager.NO_VERTICAL_SCROLL);
_text = text;
Background background = BackgroundFactory.createSolidBackground(color);
setBackground(background);
maintitle = new LabelField(_text, Field.FIELD_VCENTER | Field.FIELD_HCENTER);
Font font = Font.getDefault().derive(Font.BOLD, 35);
maintitle.setFont(font);
add(maintitle);
}
protected void sublayout(int width, int height) {
width = Math.min(width, getPreferredWidth());
height = Math.min(height, getPreferredHeight());
setExtent(width, height);
}
public int getPreferredHeight() {
return FIELD_HEIGHT;
}
public int getPreferredWidth() {
return Display.getWidth();
}
public void paint(Graphics graphics) {
int rectHeight = getPreferredHeight();
int rectWidth = getPreferredWidth();
graphics.drawRect(0, 0, rectWidth, rectHeight);
super.paint(graphics);
}
}
虽然我add(maintitle)
但它没有出现在垂直场的中间。