开发者

Get list item row to wrap instead of show ellipsis

开发者 https://www.devze.com 2023-04-10 16:08 出处:网络
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 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  = pr开发者_如何学GoeferredWidth - (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());
}

Get list item row to wrap instead of show ellipsis

Get list item row to wrap instead of show ellipsis


  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

Get list item row to wrap instead of show ellipsis

0

精彩评论

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

关注公众号