0

我试图实现如下所示的屏幕:

在此处输入图像描述

为此,我正在使用以下代码。它根本不起作用。

HorizontalFieldManager outerManager = new HorizontalFieldManager(FIELD_BOTTOM|USE_ALL_HEIGHT);
        outerManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("img/bghome.png")));

final FCLabelField selectedLabel = new FCLabelField("Hello World", LabelField.USE_ALL_WIDTH | DrawStyle.HCENTER);

selectedLabel.setFontColor(Color.BLACK);
selectedLabel.setBackground(BackgroundFactory.createSolidBackground(0x00cccccc));
outerManager.add(selectedLabel);

HorizontalFieldManager innerManager = new HorizontalFieldManager();

innerManager.setPadding(0, 10, 0, 10);


innerManager.add(new ButtonField( "Button 1", ButtonField.CONSUME_CLICK | ButtonField.FIELD_RIGHT ));
innerManager.add(new ButtonField( "Button 2", ButtonField.CONSUME_CLICK | ButtonField.FIELD_RIGHT ));
innerManager.add(new ButtonField( "Button 3", ButtonField.CONSUME_CLICK | ButtonField.FIELD_RIGHT ));
innerManager.add(tab4);
innerManager.add(tab5);

outerManager.add(innerManager);

innerManager.setBackground(BackgroundFactory.createSolidBackground(0x00cccccc));

add(outerManager);

我的代码有什么问题?我如何设置像上面这样的屏幕?

4

2 回答 2

2

有几种方法可以实现您的要求。一种方法是使用BBdevsetStatus()建议的方法(它仅适用于 type 的屏幕,不适用于 type 的屏幕)。另一种选择是手动对齐底部。MainScreenFullScreen

要记住的重要对齐规则:

  • Horizo​​ntalFieldManager 只能垂直对齐字段。向水平管理器添加字段时,只有以下对齐样式有效:FIELD_TOP、FIELD_VCENTER、FIELD_BOTTOM。

  • VerticalFieldManager 只能水平对齐字段。将字段添加到垂直字段管理器时,只有以下对齐样式有效:FIELD_LEFT、FIELD_HCENTER、FIELD_RIGHT。

这是一个代码片段,可以满足您的要求。

public class UISandbox extends MainScreen {
    public UISandbox() {
        super(NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL | USE_ALL_HEIGHT | USE_ALL_WIDTH);

        HorizontalFieldManager outerManager = new HorizontalFieldManager(USE_ALL_HEIGHT);
        outerManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("img/bghome.png")));

        VerticalFieldManager innerMngr = new VerticalFieldManager(USE_ALL_WIDTH | FIELD_BOTTOM); 
        final LabelField selectedLabel = new LabelField("Hello World", FIELD_HCENTER) {
            protected void paint(Graphics g) {
                g.setColor(Color.BLACK);
                super.paint(g);
            }
        };
        selectedLabel.setBackground(BackgroundFactory.createSolidBackground(0x00cccccc));
        innerMngr.add(selectedLabel);

        GridFieldManager innerInnerMngr = new GridFieldManager(1, 3, USE_ALL_WIDTH);
        innerInnerMngr.setPadding(10, 0, 10, 0);
        innerInnerMngr.setColumnProperty(0, GridFieldManager.AUTO_SIZE, 0);
        innerInnerMngr.setColumnProperty(1, GridFieldManager.AUTO_SIZE, 0);
        innerInnerMngr.setColumnProperty(2, GridFieldManager.AUTO_SIZE, 0);
        innerInnerMngr.add(new ButtonField("Button 1", ButtonField.CONSUME_CLICK | FIELD_HCENTER));
        innerInnerMngr.add(new ButtonField("Button 2", ButtonField.CONSUME_CLICK | FIELD_HCENTER));
        innerInnerMngr.add(new ButtonField("Button 3", ButtonField.CONSUME_CLICK | FIELD_HCENTER));

        innerMngr.add(innerInnerMngr);
        outerManager.add(innerMngr);
        add(outerManager);
    }
}
于 2012-03-22T11:55:13.647 回答
2

尝试将所有按钮添加到一个中HorizontalFieldManager,并使用 setStatus(您已添加按钮的 hfmIn)。这将在屏幕底部设置按钮。并在 setStatus 之前添加 labelField Hello world。而已。:)

于 2012-03-22T11:19:14.467 回答