非常にシンプルなオンライン チャット ルーム アプリを構築しています。私が達成したことは、現在以下のようなものです:
Robert:blah..
Tom: yes blah..
David(You): That sounds cool!
Lily: Do you know blah...
Robert:blah..
Robert:blah..
David(You): Wow! Blah...
私が直面している新しい機能/問題は、現在のユーザーのトークを右側に表示したいということです。以下のように (これは David が画面に表示するものです):
Robert:blah..
Tom: yes blah..
That sounds cool! : David(You)
Lily: Do you know blah...
Robert:blah..
Robert:blah..
Wow! Blah... : David(You)
上記の各行は TextView であり、新しいメッセージがあるたびに動的に TextView を作成し、LinearLayout
これらの TextView を含む にそれらを追加しています。David(現在のユーザー)の話を右にするために、 align right を設定して、 を に変更しLinearLayout
ましたRelativeLayout
。しかし、一度使用するRelativeLayout
と、高さを設定しなかったため、すべてのトークが同じ行に重なっていることに気付きました..これを達成する方法について誰か光を当てることができますか? 以下の私のコード:
...
//new messages are stored in lines[]
for (int i = 0; i < lines.length; i++) {
TextView newLine = new TextView(getBaseContext());
newLine.setText(lines[i]);
// check if the speaker of this line is user himself
if (speakerName.equals(userName)) {
//change the layout of this textView to make it align right..
}
myLinearView.addView(newLine);//add to linearView that contains these talks
}