黑莓 - 自定义尺寸 EditField
我正在尝试组合一个应如下所示的对话框:
填写以下字段
_______________ 喜欢 ____________________,
其中“_”行是编辑字段。
我将所有字段粘贴到 HorizontalFieldManager 中,并将其添加到对话框中。不幸的是,第一个 EditField 占用了第一行的所有空间。我尝试通过创建自己的扩展 BasicEditField 的类来重写 EditField 的 getPreferredWidth() 方法,但没有成功。
当然,必须有一种简单的方法来强制编辑字段具有一定的大小。我缺少什么?
I am trying to put together a dialog that should look like this:
Fill in the below fields
_______________ likes ____________________
where the "_" lines are the EditFields.
I am sticking all the fields in a HorizontalFieldManager, which I add to the dialog. Unfortunately, the first EditField consumes all the space on the first line. I have tried to override the getPreferredWidth() method of the EditField by creating my own class extending BasicEditField, but have had no success.
Surely there must be a simple way to force a certain size for an edit field. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如戴夫约翰斯顿所说:
Just like DaveJohnston said:
尝试子类化 HorizontalFieldManager 并重写 sublayout 方法:
在此方法中,您应该为要添加的每个组件调用 setPositionChild() 和 layoutChild() ,以便可以控制每个组件的位置和大小。
您还应该重写每个组件的布局方法,并调用
它,这将利用您已经编写的 getPreferred... 方法的实现。
希望这有帮助。
Try subclassing HorizontalFieldManager and override the sublayout method:
In this method you should call setPositionChild() and layoutChild() for each component you are adding so you can control the positioning and size of each.
You should also override the layout method of each component and call
this will make use of your implementation of the getPreferred... methods you have already written.
Hope this helps.
基于 Max Gontar 的解决方案,这应该可以解决为 HorizontalFieldManagers 的子字段分配宽度的一般问题:
只需调用 add 方法的重载即可指定宽度以及下一个字段之前的偏移空间。尽管这不允许删除/替换字段。
令人烦恼的是,RIM 在标准库中没有提供此功能。 HorizontalFieldManager应该以这种方式工作。
Building on Max Gontar's solution, this should solve the general problem of assigning width to sub Fields of HorizontalFieldManagers:
Just call the overloads of the add method to specify the width, and the offset space before the next Field. Though this does not allow for deleting/replacing Fields.
It is irksome that RIM does not provide this functionality in the standard library. HorizontalFieldManager should just work this way.