1

how to put 4 button in row, as in the picture:

enter image description here

The distance between the elements should be changed at different resolutions

4

3 回答 3

1

There are allot of ways to do everything in LWUIT. Its unclear from your image what your exact constraints are, I'm guessing you want the left most button to be left aligned and the right most to be right aligned. You probably also want the two other buttons to be centered.

I would implement this using a GridLayout with nested FlowLayout elements. As such:

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

Play with setMargin(Component.RIGHT,x) for the first three Buttons. Set the value of x such that the Buttons are equi-partitioned in the row : you must take into account the preferredWidth of the Buttons for that. For the first Button set its margin-left to 0 ( setMargin(Component.LEFT,0) ) , and for the last Button set its right-margin to 0 ( setMargin(Component.RIGHT,0) ).

于 2011-11-18T12:10:35.107 回答
0

You should use use BorderLayout and add the container (described in this answer inside south)

于 2011-11-18T23:21:49.193 回答