LabelField OS 4.5和6.0之间的不同行为

时间:2012-02-08 09:59:39

标签: blackberry labelfield

在我的应用程序中,我必须实现从VerticalFieldManager扩展的自定义组件,并且此管理器保存为Horizo​​ntalFieldManager的行。 问题出在OS 4.5中左边的LabelField只显示一行文本。这是代码和图像。BB6.0     enter image description here

class Row extends HorizontalFieldManager{
    private LabelField key;
    private LabelField value;

    public Row(String left,String right){
        key = new LabelField(left + ": ",Field.NON_FOCUSABLE | Field.NON_SPELLCHECKABLE | TextField.NO_LEARNING | RichTextField.USE_TEXT_WIDTH){
            public int getPreferredWidth() {
                return Math.min((Display.getWidth()-20)/2,super.getPreferredWidth());
            }
        };
        key.setPadding(0, 0, 0, 10);
        key.setFont(Fonts.NORMAL);
        add(key);

        value = new LabelField(right,Field.NON_SPELLCHECKABLE | TextField.NO_LEARNING | Field.FOCUSABLE);
        value.setPadding(0, 10, 0, 0);
        value.setFont(Fonts.BOLD);
        add(value);
    }
    public int getPreferredHeight() {
        return Math.max(key.getHeight(), value.getHeight());
    }
    public int getPreferredWidth() {
        return Display.getWidth()-20;
    }
    protected void sublayout(int arg0, int arg1) {
        super.sublayout(arg0, arg1);
        setExtent(getPreferredWidth(), getPreferredHeight());
    }
}

1 个答案:

答案 0 :(得分:1)

我通过将LabelFields放在VFM中并覆盖了我来解决了这个问题 getPreferredHeight()sublayout()方法如下所示。谢谢Mister Smith

class Row extends HorizontalFieldManager{
    private LabelField key;
    private LabelField value;

    public Row(String left,String right){
        VerticalFieldManager leftVfm = new VerticalFieldManager(){
            public int getPreferredWidth() {
                return Math.min(getField(0).getPreferredWidth(), (Display.getWidth())/2);
            }
            protected void sublayout(int maxWidth, int maxHeight) {
                super.sublayout(getPreferredWidth(), maxHeight);
                setExtent(getPreferredWidth(), maxHeight);
            }
        };
        VerticalFieldManager rightVfm = new VerticalFieldManager();

        key = new LabelField(label.getLabel() + ": ",Field.FOCUSABLE);
        key.setFont(Fonts.NORMAL);
        leftVfm.add(key);

        value = new LabelField(label.getRight(),Field.FOCUSABLE);
        value.setFont(Fonts.BOLD);
        rightVfm.add(value);

        add(leftVfm);
        add(rightVfm);
    }
    public int getPreferredHeight() {
        if (key != null)
            return Math.max(key.getHeight(), value.getHeight());
        else{
            return value.getHeight();
        }
    }
    public int getPreferredWidth() {
        return Display.getWidth()-20;
    }
    protected void sublayout(int arg0, int arg1) {
        super.sublayout(arg0, arg1);
        setExtent(getPreferredWidth(), getPreferredHeight());
    }
}