设置黑莓中标签字段的宽度

发布于 2024-10-07 17:48:08 字数 32 浏览 0 评论 0原文

如何在 Blackberry 中设置标签字段宽度?

How can I set the width of a label field width in Blackberry?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

入怼 2024-10-14 17:48:08

好吧,如果你只是想要一些快速而肮脏的东西,这应该可以完成工作:

LabelField lField = new LabelField("text")
    {
        protected void layout(int width, int height) {
            super.layout(width, height);
            this.setExtent(HARD_CODED_WIDTH, this.getHeight());
        }
    };

但正确的方法是选择(或编写)一个布局管理器,它可以做你想要的事情,并具有一定的灵活性,以适应不同的屏幕尺寸和其他事情。 RIM 有一些关于编写您自己的管理器的不错的示例。搜索 JustifiedEvenlySpacedHorizo​​ntalFieldManager。或者看看 Thinking blackberry:http://www.thinkingblackberry.com/archives/116

Well if you just want something quick and dirty, this should do the job:

LabelField lField = new LabelField("text")
    {
        protected void layout(int width, int height) {
            super.layout(width, height);
            this.setExtent(HARD_CODED_WIDTH, this.getHeight());
        }
    };

But the right way to do it is choose (or write) a layout manager that does what you want with some flexibility to account for different screen sizes and other things. RIM has a few decent samples up on writing your own manager. Search for JustifiedEvenlySpacedHorizontalFieldManager. Or take a look at thinking blackberry: http://www.thinkingblackberry.com/archives/116

简美 2024-10-14 17:48:08

cjp的答案是正确的,但我正在添加更多内容。

如果您的文本长度更长并且使用上面的代码进行剪切,那么您可以像下面的代码一样执行操作:

LabelField lField = new LabelField("text")
{
    protected void layout(int width, int height) {
        super.layout(width, height);
        this.setExtent(HARD_CODED_WIDTH, this.getHeight());
    }
    public int getPreferredWidth() {
    return HARD_CODED_WIDTH;
}
};

如果文本长度大于您定义的宽度,则上面的代码将不会剪切文本。在这种情况下,文本将进入下一行。

希望你明白了。

cjp's answer is corrent but i am adding more in to it.

If your text length is more and getting cut in with above code then you can do like below code:

LabelField lField = new LabelField("text")
{
    protected void layout(int width, int height) {
        super.layout(width, height);
        this.setExtent(HARD_CODED_WIDTH, this.getHeight());
    }
    public int getPreferredWidth() {
    return HARD_CODED_WIDTH;
}
};

Above code will not cut the text if the text length is more then the width you have define. And in that case the text get to the next line.

Hope you got the point.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文