1

写真のように、4つのボタンを一列に並べる方法:

ここに画像の説明を入力

要素間の距離は、異なる解像度で変更する必要があります

4

3 に答える 3

1

LWUIT ですべてを行う方法はたくさんあります。あなたのイメージからあなたの正確な制約が何であるかは不明です。左端のボタンを左揃えにし、右端のボタンを右揃えにしたいと思います。おそらく、他の 2 つのボタンも中央に配置する必要があります。

GridLayoutネストされたFlowLayout要素を使用してこれを実装します。そのような:

Container c = new Container(new GridLayout(1, 4));
addButton(c, new Button("b1"), Component.LEFT);
addButton(c, new Button("b2"), Component.CENTER);
addButton(c, new Button("b3"), Component.CENTER);
addButton(c, new Button("b4"), Component.RIGHT);


private void addButton(Container c, Button b, int align) {
   Container flow = new Container(new FlowLayout(align));
   flow.addComponent(b);
   c.addComponent(flow);
}
于 2011-11-20T07:48:25.607 に答える
0

use を使用BorderLayoutしてコンテナを追加する必要があります(南のこの回答で説明されています)

于 2011-11-18T23:21:49.193 に答える
0

setMargin(Component.RIGHT,x)最初の 3 つのボタンで遊んでください。xButtons が 行 : で等分割されるようにの値を設定しますyou must take into account the preferredWidth of the Buttons for that。最初の Button では margin-left を 0 ( setMargin(Component.LEFT,0)) に設定し、最後の Button では right-margin を 0 ( setMargin(Component.RIGHT,0)) に設定します。

于 2011-11-18T12:10:35.107 に答える