写真のように、4つのボタンを一列に並べる方法:
要素間の距離は、異なる解像度で変更する必要があります
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);
}
use を使用BorderLayout
してコンテナを追加する必要があります(南のこの回答で説明されています)
setMargin(Component.RIGHT,x)
最初の 3 つのボタンで遊んでください。x
Buttons が 行 : で等分割されるようにの値を設定します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)
) に設定します。