1

我想EditField在我的 BlackBerry 应用程序中设置 的高度和宽度。

4

4 回答 4

8

您需要覆盖字段的布局方法来为您设置大小:

protected void layout(int width, int height)
{
    super.layout(customWidth, customHeight);
    setExtent(customWidth, customHeight);
}

您在其他地方设置的位置customWidth和位置。customHeight

  • super.layout(customWidth, customHeight)布置场地以使用您的特殊宽度和高度。

  • setExtent(customWidth, customHeight)设置屏幕上字段的大小。


当您使用类似于以下代码的代码声明您的 EditField 时,您可以执行此操作:

final int customWidth = Display.getWidth();
final int customHeight = 30;

Field myEditField = new EditField()
{
    protected void layout(int width, int height)
    {
        super.layout(customWidth, customHeight);
        setExtent(customWidth, customHeight);
    }

};
于 2011-11-17T13:13:00.637 回答
3

您还可以在水平字段管理器中调整编辑字段并覆盖子布局方法以设置水平字段管理器的高度和宽度以设置编辑字段的高度和宽度

于 2011-12-01T10:44:18.107 回答
1
  • 注意1:您不能设置宽度和高度editField
  • 注意2:您只使用sublayout 管理器中的方法
  • 注意 3 :如果您添加editField 到屏幕,它将填充从屏幕开始到结束的所有可用宽度

您可以通过将一些字段放在左侧并将您editField的放在最后来使用这个想法。

或者,您可以使用以下代码。

您将设置管理器和编辑字段的宽度和高度,并尝试将它们放在屏幕上:

HorizontalFieldManager containerManager = new HorizontalFieldManager() {
    public int getPreferredHeight() {
        return super.getPreferredHeight();
    }

    public int getPreferredWidth() {
        return super.getPreferredWidth();
    } 

    protected void sublayout(int maxWidth, int maxHeight) {
        setExtent(getPreferredWidth(), getPreferredHeight());
        super.sublayout(getPreferredWidth(), getPreferredHeight());
    }
};


EditField editField = new EditField(Field.FIELD_VCENTER) {
    public int getPreferredHeight() {
        // TODO Auto-generated method stub
        return super.getPreferredHeight();
    }

    public int getPreferredWidth() {
        // TODO Auto-generated method stub
        return super.getPreferredWidth();
    } 
};
于 2012-11-11T18:48:10.077 回答
0

修改 EditField 高度的另一种方法是摆弄边框周围的填充,如下所示:

EditField emailField = new EditField("", "optional initial text");

XYEdges xyEdge = new XYEdges(2, 2, 2, 2);
XYEdges xyEdgeColors = new XYEdges(0x00dddddd, 0x00dddddd, 0x00dddddd, 0x00dddddd);
Border aBorder = BorderFactory.createSimpleBorder(xyEdge, xyEdgeColors, Border.STYLE_SOLID);

emailField.setBorder(aBorder);
emailField.setPadding(10, 5, 5, 10);
于 2012-11-27T20:29:19.237 回答