1
我嘗試實現一個Chat window
(聊天功能工作正常&光滑)。我在設計Middle & Bottom part
時遇到問題。在middle part chat messages
&底部我想添加可編輯字段。如果我修改了可編輯字段對齊底部聊天消息不顯示,&如果我在底部添加可編輯字段,然後聊天消息顯示在屏幕上。我已經使用NegativeMarginVerticalFieldManager。聊天窗口設計 - 黑莓
我想要字段附加在屏幕的底部&消息顯示中間與滾動條。在這裏,我還附上了我用於與虛擬消息聊天的聊天代碼(沒有Json數據)。由於
package mypackage;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.*;
public class ChatList extends MainScreen
{
Manager _foreground = new NegativeMarginVerticalFieldManager(USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL);
BasicEditField msg;
public ChatList() {
super(NO_VERTICAL_SCROLL);
setTitle("Chat");
// Set the linear background.
this.getMainManager().setBackground(
BackgroundFactory.createLinearGradientBackground(0x91e7ff,0x0099CCFF,0x00336699,0x91e7ff)
);
// Add Field Bottom
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH);
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_WIDTH | FIELD_BOTTOM);
msg = new BasicEditField();
msg.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x999999, Border.STYLE_FILLED));
msg.setBackground(BackgroundFactory.createSolidBackground(0xe0e0e0));
msg.setPadding(5,0,5,0);
msg.setMargin(0,10,0,10);
vfm.add(msg);
hfm.add(vfm);
add(hfm);
}
public boolean keyDown(int keycode, int time) {
if (Keypad.KEY_ENTER == Keypad.key(keycode)) {
String message = msg.getText();
if(!message.equals(""))
{
Border rightBorder = BorderFactory.createBitmapBorder(new XYEdges(16, 23, 27, 16), Bitmap.getBitmapResource("border_bubble_right.png"));
Border leftBorder = BorderFactory.createBitmapBorder(new XYEdges(16, 16, 27, 23), Bitmap.getBitmapResource("border_bubble_left.png"));
addHeading("Hello Adil!", leftBorder, Field.FIELD_LEFT);
addHeading("Yeah, I see it", rightBorder, Field.FIELD_RIGHT);
addHeading("have any update , related to this??", leftBorder, Field.FIELD_LEFT);
addHeading("No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT);
addHeading("Middle part Messages", leftBorder, Field.FIELD_LEFT);
addHeading("Vertically Scroll add in messages", leftBorder, Field.FIELD_LEFT);
addHeading("have any update!", rightBorder, Field.FIELD_RIGHT);
addHeading("Better get on that", leftBorder, Field.FIELD_LEFT);
addHeading("No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT);
addHeading("Bottom Alignment Basic Editable Field?", leftBorder, Field.FIELD_LEFT);
addHeading("Probably", rightBorder, Field.FIELD_RIGHT);
addHeading("Better get on that", leftBorder, Field.FIELD_LEFT);
addHeading("No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT);
msg.setText("");
// ADD ALL FIELDS
add(_foreground);
}// if condition
else{ Dialog.alert("Please insert message");}
return true;
}
//let the system to pass the event to another listener.
return false;
}
private void addHeading(String label, Border border, long style)
{
LabelField header = new LabelField(label, Field.FOCUSABLE | style);
header.setBorder(border);
header.setMargin(5, 5, -15, 5);
_foreground.add(header);
}
}
感謝@signare!但在中間部分,消息不顯示在屏幕上?正在顯示消息 –
。只需點擊發送按鈕,就會顯示消息。 – Signare
謝謝@Signare!它在設備上工作正常,首先我在模擬器上檢查它。 –