Получить строку списка элементов для переноса вместо отображения многоточия - PullRequest
1 голос
/ 04 октября 2011

Я использовал приведенный ниже код, чтобы получить макет, который форматирует изображение, заголовок и текстовую область в элементе списка.
Мне бы хотелось, чтобы он выглядел как макет приложений 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());
}

My code produces

The desired effect

1 Ответ

1 голос
/ 22 февраля 2012
  1. Во-первых, вам нужно избавиться от стиля ELLIPSIS, как предложил icchanobot.
  2. Затем вам нужно добавить поле метки в VerticalFieldManager (HorizontalFieldManager тоже будет работать), как предложено в этом ответе.

Следующий фрагмент кода

String longString = "This is a LabelField inside a VerticalFieldManager. Here is a link to your question /5885917/poluchit-stroku-spiska-elementov-dlya-perenosa-vmesto-otobrazheniya-mnogotochiya";

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


производит

enter image description here

...