黑莓priv与水平FieldManager中的FIELD BUTTON

时间:2012-03-22 11:12:42

标签: user-interface blackberry button horizontalfieldmanager

我试图实现如下屏幕:

enter image description here

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

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);

我的代码有什么问题?我如何设置如上所示的屏幕?

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:2)

有几种方法可以实现您的要求。一种方法是使用setStatus()方法作为 BBdev 建议(它仅适用于MainScreen类型的屏幕,不适用于FullScreen类型的屏幕)。另一种方法是手动对齐底部

要记住的重要对齐规则:

  • 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);
    }
}