如何使用 lwuit 将 4 个按钮排成一行?在同样的距离
如何在行中放置 4 个按钮,如图所示:
元素之间的距离应更改为不同的分辨率
how to put 4 button in row, as in the picture:
The distance between the elements should be changed at different resolutions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 LWUIT 中,有多种方法可以完成所有操作。从你的图像中不清楚你的确切限制是什么,我猜你希望最左边的按钮左对齐,最右边的按钮右对齐。您可能还希望其他两个按钮居中。
我将使用带有嵌套
FlowLayout
元素的GridLayout
来实现此功能。像这样: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 nestedFlowLayout
elements. As such:对前三个按钮使用
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 ofx
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)
).您应该使用
BorderLayout
并添加容器(描述在这个答案内南)You should use use
BorderLayout
and add the container (described in this answer inside south)