Blackberry setting the position of a RichtextField in FullScreen

こ雲淡風輕ζ 提交于 2019-12-13 03:18:20

问题


I am writing an application in BlackBerry, where I want to do some custom painting at the top portion of the screen in the paint method of FullScreen and at the same time, I want a RichtextField positioned at the lower portion of the screen. I tried using setPosition methods in the Field class, but to no avail. So how do I set the position of the RichtextField that is added to the FullScreen class?


回答1:


You can use a SpacerField for that purpose:

class SpacerField extends Field {

  int localWidth, localHeight;

  SpacerField(int width, int height) {
    super(Field.NON_FOCUSABLE);
    localWidth = width;
    localHeight = height;
  }

  protected void layout(int width, int height) {
    // TODO Auto-generated method stub
    setExtent(localWidth, localHeight);
  }


  protected void paint(Graphics graphics) {

  }


  public int getPreferredWidth() {
    return localWidth;
  }

  public int getPreferredHeight() {
    return localHeight;
  }
}

and add it to your Screen before your RichTextField. Be sure to give a suitable width (Display.getWidth() ?) and height when constructing the SpacerField.

Note: I had found the code at this forum discussion a few months ago when I needed to do something similar.




回答2:


The best way to position objects is to extend a Manager and use it to position and size the objects the way you want. Check the documentation for net.rim.device.api.ui.Manager and net.rim.device.api.ui.Field for information on how manager control their children.



来源:https://stackoverflow.com/questions/1305607/blackberry-setting-the-position-of-a-richtextfield-in-fullscreen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!