获取列表项行换行而不是显示省略号

发布于 2024-12-07 14:33:35 字数 1637 浏览 0 评论 0原文

我使用下面的代码来生成一个布局,用于格式化列表项中的图像、标题和文本区域。
我想让它看起来像 Twitter 应用程序的布局 - 就如何让推文换行而言,我错过了什么?

平台详情: BB OS 5.0+

代码:

protected void sublayout(int width, int height) {
    try {
        deleteAll();
    } catch (Exception ex) {

    }

    MyTitleField lblTitle = new MyTitleField(info.title);//extends LabelField
    LabelField lblDesc = new LabelField(info.description , LabelField.ELLIPSIS)
    {
        protected void layout(int width, int height) {
            // TODO Auto-generated method stub
            super.layout(width, height);
        }
    };

    BitmapField bmfIcon = new BitmapField(info.icon);
    add(lblTitle);
    add(lblDesc);
    add(bmfIcon);

    int iconHeight = bmfIcon.getBitmapHeight();
    int fontHeight = Font.getDefault().getHeight();
    int preferredWidth = width;//getPreferredWidth();

    int startY = (rowHeight - iconHeight)/2;
    layoutChild(bmfIcon, bmfIcon.getBitmapWidth(), bmfIcon.getBitmapHeight());
    setPositionChild(bmfIcon, 5, startY);

    int textWidth  = preferredWidth - (bmfIcon.getBitmapWidth() +10 );
    int textStartX = bmfIcon.getBitmapWidth() + 10;
    layoutChild(lblTitle, textWidth  ,
            fontHeight + 1);
    setPositionChild(lblTitle, textStartX, startY);

    int descHeight = rowHeight - (startY+fontHeight+2);
    layoutChild(lblDesc, textWidth  , descHeight);

    setPositionChild(lblDesc, textStartX, (startY+fontHeight+2));

    setExtent(preferredWidth, getPreferredHeight());
}

我的代码生成

所需效果

I used the code below to get produce a layout that formats an image, a title and a text region in a list item.
I would like to get it to look like the Twitter apps layout - in terms of how it gets the tweet to wrap, what am I missing?

Platform details:
BB OS 5.0+

Code:

protected void sublayout(int width, int height) {
    try {
        deleteAll();
    } catch (Exception ex) {

    }

    MyTitleField lblTitle = new MyTitleField(info.title);//extends LabelField
    LabelField lblDesc = new LabelField(info.description , LabelField.ELLIPSIS)
    {
        protected void layout(int width, int height) {
            // TODO Auto-generated method stub
            super.layout(width, height);
        }
    };

    BitmapField bmfIcon = new BitmapField(info.icon);
    add(lblTitle);
    add(lblDesc);
    add(bmfIcon);

    int iconHeight = bmfIcon.getBitmapHeight();
    int fontHeight = Font.getDefault().getHeight();
    int preferredWidth = width;//getPreferredWidth();

    int startY = (rowHeight - iconHeight)/2;
    layoutChild(bmfIcon, bmfIcon.getBitmapWidth(), bmfIcon.getBitmapHeight());
    setPositionChild(bmfIcon, 5, startY);

    int textWidth  = preferredWidth - (bmfIcon.getBitmapWidth() +10 );
    int textStartX = bmfIcon.getBitmapWidth() + 10;
    layoutChild(lblTitle, textWidth  ,
            fontHeight + 1);
    setPositionChild(lblTitle, textStartX, startY);

    int descHeight = rowHeight - (startY+fontHeight+2);
    layoutChild(lblDesc, textWidth  , descHeight);

    setPositionChild(lblDesc, textStartX, (startY+fontHeight+2));

    setExtent(preferredWidth, getPreferredHeight());
}

My code produces

The desired effect

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

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

发布评论

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

评论(1

归属感 2024-12-14 14:33:35
  1. 首先,您需要按照 icchanobot 的建议摆脱 ELLIPSIS 风格。
  2. 然后,您需要按照 这个答案。

以下代码片段

String longString = "This is a LabelField inside a VerticalFieldManager. Here is a link to your question https://stackoverflow.com/questions/7641753/get-list-item-row-to-wrap-instead-of-show-ellipsis";

VerticalFieldManager vfm = new VerticalFieldManager(Manager.USE_ALL_WIDTH | Manager.NO_HORIZONTAL_SCROLL);
vfm.add(new LabelField(longString));
add(vfm);

产生

在此处输入图像描述

  1. First, you need to get rid of ELLIPSIS style as icchanobot suggested.
  2. Then you need to add your label field inside a VerticalFieldManager (HorizontalFieldManager will work too) as suggested in this answer.

The following code snippet

String longString = "This is a LabelField inside a VerticalFieldManager. Here is a link to your question https://stackoverflow.com/questions/7641753/get-list-item-row-to-wrap-instead-of-show-ellipsis";

VerticalFieldManager vfm = new VerticalFieldManager(Manager.USE_ALL_WIDTH | Manager.NO_HORIZONTAL_SCROLL);
vfm.add(new LabelField(longString));
add(vfm);

produces

enter image description here

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