我使用下面的代码生成了一个布局,用于格式化列表项中的图像、标题和文本区域。
我想让它看起来像 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());
}