Layout Manager

Layout Manager

n         作用:决定组件在容器内的位置和大小。

n         几个常用的

n         FlowLayout    :组件按行摆放。每一个组件都赋予了它的建议的大小。当一行有许多元素无法放到一起,则会开始新的一行

u       常用方法

l         New FlowLayout()

l         New FlowLayout(int algn)

l         New FlowLayout(int algn, int hgap, int vgap)

n         BorderLayout :将容器分为三个水平带:上中下。大多数情况下,一个组件被放置在上或者下。这些元素被赋予了建议的高度,但是他们占据了容器的全部宽度。中间的部分被分为三个部分,左中右。它的高度是减掉上下部分所剩下的。左右组件被赋予了建议的宽度,但是他们占据了中间地带的所有高度。

u       常用方法

l         New BorderLayout ()

l         New BorderLayout(int hgap, int vgap)

n         GridLayout :将组件放置在一个长方形的网格中,每个小格大小是一样的

u       常用方法:

l         New GridLayout(int rows, int cols)

l         New GridLayout(int rows ,int cols , int hgpa, int vgap)

n         BoxLayout :将组件放在一行或者一列,

u       常用方法:

l           new BoxLayout(Component c, BoxLayout.X_AXIS)

l           new BoxLayout(Component c, BoxLayout.Y_AXIS)

 

J2me Form layout 策略:

n         负责集合里面控件的布局,遍历和滚动

n         通过 Index 索引控件

n         当容器里面的控件增减时候,应用程序无需采取额外的动作来刷新显示

n         Layout 策略按照行管理。

n         行宽通常与屏幕的宽度一致,考虑边界,滚动条等等。所有的行都有一样的宽度。通常 form 不用水平滚动

n         行的高度由里面的控件决定,无需所有行高度一致

n         Left-to-right , Right-to-Left 的排列

n         当前对齐方式。 LAYOUT_LEFT , LAYOUT_CENTER , or LAYOUT_RIGHT

n         换行的出现:

u       控件之前:

l         当 前一个控件后面有一个换行

l         当 当前控件是LAYOUT_NEWLINE_BEFORE

l         当 当前控件是stringItem 而且内容以’/n’ 开始

l         当 当前控件是ChoiceGroup,DateFieldGauge. 或者TextField, 而且不是LAYOUT_2

l         当 当前控件是LAYOUT_LEFT,LAYOUT_CENTER,LAYOUT_RIGHT, 并且不同于FORM 的的当前对齐方式

u       控件之后:

l         当前控件是 StringItem 而且用 ’/n’ 结束

l         当前控件是 LAYOUT_NEWLINE_AFTER

l         当前控件是 choiceGroup, DateField Gauge TextField., 而且 LAYOUT_2 没有设置

u       补充说明:

l         如果当前已经有一个换行指令的话,则 LAYOUT_NEWLINE_BEFORE,LAYOUT_NEWLINE_AFTER 并不会导致额外的换行。如果有多个连续的‘ /n ‘,则会导致相应的换行。

n         当将新控件放到一行,总是将剩下的位置和控件的宽度进行比较,如果任何一个控件是 LAYOUT_SHRINK 的,则会使用控件的        最小宽度,否则使用控件的最佳宽度。如果剩下的宽度不足,则会导致新的换行。

n         当一行的内容确定下来之后,剩下的宽度通过拉宽控件和添加控件间距来使用掉。如果任何一个控件是 LAYOUT_SHRINK ,则这些空间首先分配给它们。空间根据控件的最佳宽度和最小宽度之间的差值,按比例分配。如果当所有的可缩的控件都达到了最佳宽度,仍然有空间剩余,剩下的空间分配给 LAYOUT_EXPAND 的控件。否则将剩余的空间按照对齐方式排列在该行的“最后”(同一行的所有控件必然具有相同的对齐方式)

n         一行最高的控件的高度决定了该行的高度,所有控件按照自己的最佳高度显示,除非有 LAYOUT_VSHRINK (这种情况下使用的是最小高度)。 LAYOUT_VSHRINK 的控件,拉伸到它们的最佳高度或者是该行的高度。如果控件是 LAYOUT_VEXPAND 而且高度比当前行的高度小,则拉伸到该行的高度。其他的控件会根据 LAYOUT_TOP LAYOUT_BOTTOM,LAYOUT_VCENTER 对齐方式摆放。

u       StringItem 必须特殊处理,如果内容有一个 ’/n’ 则必须在该行断开,剩下内容在下一行开始布局,如果一个或者两个维度的最佳大小被锁定,则 stringItem 被包围起来在一个长方体里面。这时候 LAYOUT_SHRINK,LAYOUT_EXPAND,LAYOUT_VEXPAND 被忽略。“ If both dimensions of the preferred size of a StringItem are unlocked, the text from the StringItem may be wrapped across multiple rows. At the point in the layout algorithm where the width of the Item is compared to the remaining space on the row, as much text is taken from the beginning of the StringItem as will fit onto the current row. The contents of this row are then positioned according to the current alignment value. The remainder of the text in the StringItem is line-wrapped to the full width of as many new rows as are necessary to accommodate the text. Each full row is positioned according to the current alignment value. The last line of the text might leave space available on its row. If there is no row break following this StringItem , subsequent Items are packed into the remaining space and the contents of the row are positioned according to the current alignment value. This rule has the effect of displaying the contents of a StringItem as a paragraph of text set flush-left, flush-right, or centered, depending upon whether the current alignment value is LAYOUT_LEFT , LAYOUT_RIGHT , or LAYOUT_CENTER , respectively. The preferred width and height of a StringItem wrapped across multiple rows, as reported by the Item.getPreferredWidth and Item.getPreferredHeight methods, describe the width and height of the bounding rectangle of the wrapped text.

n         Layout 策略的调用时间

u       A Form's layout is recomputed automatically as necessary. This may occur because of a change in an Item's size caused by a change in its contents or because of a request by the application to change the Item's preferred size. It may also occur if an Item's layout directives are changed by the application. The application does not need to perform any specific action to cause the Form's layout to be updated.

n         Line Breaks and Wrapping

u       For all cases where text is wrapped, line breaks must occur at each newline character ('/n' = Unicode 'U+000A'). If space does not permit the full text to be displayed it is truncated at line breaks. If there are no suitable line breaks, it is recommended that implementations break text at word boundaries. If there are no word boundaries, it is recommended that implementations break text at character boundaries.

u       Labels that contain line breaks may be truncated at the line break and cause the rest of the label not to be shown.

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值