1

EditFieldBlackBerryアプリでの高さと幅を設定したい。

4

4 に答える 4

8

サイズを設定するには、フィールドのレイアウトメソッドをオーバーライドする必要があります。

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

どこでcustomWidthcustomHeight他の場所であなたによって設定されています。

  • 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

また、horizo​​ntalFieldmanager内の編集フィールドのペースを調整し、sublayoutメソッドをオーバーライドして、編集フィールドの高さと幅を設定するためのhorizo​​ntalfieldmanagerの高さと幅を設定することもできます。

于 2011-12-01T10:44:18.107 に答える
1
  • 注 1 : 幅と高さを設定することはできません。editField
  • sublayout 注2:マネージャーでメソッドのみを使用します
  • 注 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 に答える