如何使用 lwuit 将 4 个按钮排成一行?在同样的距离

发布于 2024-12-16 21:20:18 字数 121 浏览 4 评论 0原文

如何在行中放置 4 个按钮,如图所示:

在此处输入图像描述

元素之间的距离应更改为不同的分辨率

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

dawn曙光 2024-12-23 21:20:18

在 LWUIT 中,有多种方法可以完成所有操作。从你的图像中不清楚你的确切限制是什么,我猜你希望最左边的按钮左对齐,最右边的按钮右对齐。您可能还希望其他两个按钮居中。

我将使用带有嵌套 FlowLayout 元素的 GridLayout 来实现此功能。像这样:

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);
}

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);
}
不再见 2024-12-23 21:20:18

对前三个按钮使用 setMargin(Component.RIGHT,x) 。设置x 的值,使按钮在行中均匀分区:您必须为此考虑按钮的preferredWidth。对于第一个 Button,将其左边距设置为 0 ( setMargin(Component.LEFT,0) ) ,对于最后一个 Button,将其右边距设置为 0 ( setMargin(Component.RIGHT) ,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) ).

酷到爆炸 2024-12-23 21:20:18

您应该使用 BorderLayout 并添加容器(描述在这个答案内南)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文