How get height of title screen on blackberry screen?

僤鯓⒐⒋嵵緔 提交于 2019-12-11 08:53:25

问题


Why getHeight after setTitle equal null? How do I get the actual height value?

public class ActivityScreen extends MainScreen {
    /**
     * Creates new instance Activity screen
     */
    public ActivityScreen() {
      super();
          TitleFieldManager titleField = new TitleFieldManager(Display.getWidth());
          super.setTitle(titleField);
          if (titleField.getHeight() == 0) {
             // Why titleField.getHeight() == 0 ?
          }
    }
}

回答1:


Because you are calling titleField.getHeight() in the screen's constructor. At this point the UI framework has not passed the layouting/measuring process for the screen yet. If for instance, you will call the same titleField.getHeight() after at least one screen's paint(Graphics graphics) call has been executed you'll be able to get a non-zero value. All layouting/measuring is guaranteedly passed BEFORE the screen content can be drawn.

Check the Manager.sublayout(int width, int height) API. MainScreen is also a Manager. So at some point AFTER the screen has been constructed, but BEFORE it is painted, the UI framework calls its sublayout(int width, int height) where all layouting/measuring happens (all child fields get their sizes).




回答2:


I'm not 100% sure of this, but I think the height of the element is calculated when the manager that contains it is laid out.

Try pushing the screen that contains that title and then calling titleField.getHeight()



来源:https://stackoverflow.com/questions/5368139/how-get-height-of-title-screen-on-blackberry-screen

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