在我的应用程序中,我必须实现从 VerticalFieldManager 扩展的自定义组件,并且该管理器包含 HorizontalFieldManager 的行。问题在于左侧的 OS 4.5 LabelField 仅显示一行文本。这是代码和图像。
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());
}
}