2

在 BlackBerry(OS 6+)中,我需要如下图所示的布局。但到目前为止,我还不能正确地得到红圈部分。

我使用了 aHorizontalFieldManager并添加了BasicEditField和​​两个ButtonFields。但是只有BasicEditField屏幕上可见,两个按钮被推出屏幕(但它们仍然是可聚焦的,尽管不可见)。

那么有什么想法吗?非常感谢任何帮助!

图像(我正在尝试做的事情用红色圈起来): 在此处输入图像描述

4

3 回答 3

3

试试这个它正在工作。

HorizontalFieldManager manager = new HorizontalFieldManager(USE_ALL_WIDTH);
    BasicEditField editField = new BasicEditField("Test", ""){
        protected void layout(int width, int height) {
            super.layout(width, height);
            setExtent(140, getPreferredHeight());
        }
    };
    manager.add(editField);
    manager.add(new ButtonField("button1"));
    manager.add(new ButtonField("button2"));
    add(manager);

在上面的 setExtent(width,height) 方法中,根据您的需要设置宽度。

于 2012-04-05T12:16:24.077 回答
2

你可以检查类MyManager。可能是同一个布局可以实现HorizontalFieldManager,但是我在使用的时候失败了好几次HorizontalFieldManager

public class MyScreen extends MainScreen {
    private BasicEditField _bef = new BasicEditField();
    private ButtonField _bf1 = new ButtonField("Button");
    private ButtonField _bf2 = new ButtonField("Button");

    public MyScreen() {
        MyManager mgr = new MyManager();
        _bef.setText("BasicEditField");
        mgr.add(_bef);
        mgr.add(_bf1);
        mgr.add(_bf2);
        add(mgr);
    }
}

class MyManager extends Manager {
    private final int HORIZONTAL_GAP = 5;

    public MyManager() {
        super(0);
    }

    protected void sublayout(int width, int height) {
        int fields = getFieldCount();
        Field field;
        int nHeight = 0;
        int remaininigWidth = width;
        int x0, x1, x2;

        // specific layout implementation only
        if (fields == 3) {
            // right most ButtonField
            field = getField(2);
            layoutChild(field, remaininigWidth, height);
            nHeight = Math.max(nHeight, field.getHeight()); 
            remaininigWidth -= (field.getWidth() + HORIZONTAL_GAP);
            x2 = remaininigWidth;

            // middle ButtonField
            field = getField(1);
            layoutChild(field, remaininigWidth, height);
            nHeight = Math.max(nHeight, field.getHeight()); 
            remaininigWidth -= (field.getWidth() + HORIZONTAL_GAP);
            x1 = remaininigWidth;

            // first BasicEditField
            field = getField(0);
            layoutChild(field, remaininigWidth, height);
            nHeight = Math.max(nHeight, field.getHeight());
            x0 = 0;

            setPositionChild(getField(0), x0, (nHeight - getField(0).getHeight()) / 2);
            setPositionChild(getField(1), x1, (nHeight - getField(1).getHeight()) / 2);
            setPositionChild(getField(2), x2, (nHeight - getField(2).getHeight()) / 2);

            setExtent(width, nHeight);
        } else {
            setExtent(width, 0);
        }

        field = null;
    }
}
于 2012-04-05T07:52:27.763 回答
1
 HorizontalFieldManager hfm = new HorizontalFieldManager();
BasicEditField editField = new BasicEditField("", ""){
    protected void layout(int width, int height) {
        super.layout(100,  getPreferredHeight());
        setExtent(100, getPreferredHeight());
    }
};
hfm.add(editField);
hfm.add(new ButtonField("button1"));
hfm.add(new ButtonField("button2"));
add(hfm);
于 2012-04-12T04:57:22.350 回答