具有自定义高度的 BlackBerry 垂直居中 LabelField
我有一个嵌套在 TableLayoutManager 行中的 LabelField。我希望该行具有特定的高度(与其位图背景的高度相同)。为了实现这一点,我更改了嵌套 LabelField 的layout() 方法:
LabelField lblHours = new LabelField(hours,
Color.BLACK, Manager.FIELD_VCENTER) {
protected void layout(int width, int height) {
super.layout(width, 40 //height of the bitmap);
setExtent(width, 40 //height of the bitmap);
}
};
这成功地增加了 TableLayoutManager 行大小。但是,一旦我这样做,LabelField 就不再在行内垂直居中。关于如何做到这一点有什么建议吗?
谢谢!
I have a LabelField nested within a TableLayoutManager row. I want the row to be a specific height (the same height as its bitmap background). In order to achieve this, I changed the layout() method of the nested LabelField:
LabelField lblHours = new LabelField(hours,
Color.BLACK, Manager.FIELD_VCENTER) {
protected void layout(int width, int height) {
super.layout(width, 40 //height of the bitmap);
setExtent(width, 40 //height of the bitmap);
}
};
This successfully increased the TableLayoutManager row size. However, once I do this, the LabelField is no longer centered vertically within the row. Any suggestions on how to do that?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上面的答案有效,只需确保您为上述内容输入两个语句即可。如下例所示。
这将是相同的回应.. 谢谢你们.. 的讨论。它帮助了我。
The above answer works just make sure that you put in two statements for the above.. as illustrated in the below example.
This is going to be the same response.. and thank you guys.. for the discussion. It helped me.
尝试将
setExtent(width, 40)
更改为setExtent(this.getWidth(), 40)
。如果 getWidth() 尝试占用所有可用宽度(这就是您的 setExtent() 调用正在执行的操作),则这可能不起作用,并且由于文本将左对齐绘制,因此看起来您的字段不是'不居中,但实际上它只是占据了表格的整个单元格。或者,如果这不起作用,您可以执行setExtent(Math.min(width, this.getFont().getAdvance(this.getText())), 40);
Try changing
setExtent(width, 40)
tosetExtent(this.getWidth(), 40)
. This could possibly not work if getWidth() is trying to take up all of the available width (which is what your setExtent() call is doing), and since the text will be drawn left-aligned, it looks like your field isn't centered but in reality it's just taking up the entire cell of your table. Alternatively, if this doesn't work you may be able to dosetExtent(Math.min(width, this.getFont().getAdvance(this.getText())), 40);