如何在黑莓屏幕上获取标题屏幕的高度? [英] How get height of title screen on blackberry screen?

查看:115
本文介绍了如何在黑莓屏幕上获取标题屏幕的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么setTitle之后的getHeight等于null? 如何获得实际的身高值?

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 ?
          }
    }
}

推荐答案

因为您正在屏幕的构造函数中调用titleField.getHeight().此时,UI框架尚未通过屏幕的布局/测量过程.例如,如果您执行了至少一个屏幕的paint(Graphics graphics)调用后将调用相同的titleField.getHeight(),您将能够获得非零值.在可以绘制屏幕内容之前,必须确保通过所有布局/测量.

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

这篇关于如何在黑莓屏幕上获取标题屏幕的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆