开发者

How get height of title screen on blackberry screen?

Why getHeight after setTitle equal null? How do I get th开发者_高级运维e 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 ?
          }
    }
}


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).


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()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜