0

私のカスタムverticalfieldmanger

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)はしかしそれは垂直フィールドの真ん中に出てきませんでした。

4

1 に答える 1

0

あなたはこれを試すことができます:

コンストラクターにフラグを追加します。

super(Manager.NO_VERTICAL_SCROLL | Manager.USE_ALL_WIDTH);

フィールドにも:

maintitle = new LabelField(DrawStyle.HCENTER | Field.FIELD_HCENTER);

これにより、フィールドが水平方向の中央に配置されます。フラグを追加して垂直方向の中央に配置することもできますが、VFMには垂直方向のスクロールに問題があるため、機能しない可能性があります。ルールは次のとおりです。水平方向に中央揃えするには、を使用しVerticalFieldManager、垂直方向に中央揃えするには、を使用しHorizontalFieldManagerます。これは、垂直方向に中央揃えする方法です。

    HorizontalFieldManager hfm = new HorizontalFieldManager(Manager.USE_ALL_HEIGHT);
    Field toCenter = new <Field>(DrawStyle.VCENTER | Field.FIELD_VCENTER );
    hfm.add(toCenter);

理論的には、両方のアプローチを組み合わせて、一方のマネージャーをもう一方のマネージャーの中にネストするソリューションを考え出すことができます。

于 2012-06-06T08:42:57.003 に答える