アプリケーションにチャットを実装する方法を探していました。着信メッセージと発信メッセージを取得する方法を既に実装しています。私の唯一の問題は、チャットのレイアウトを作成する方法です。しかし、私は本当にそれを理解することはできません。見てみると、チャットのようなレイアウトが見つかりました ( http://code.google.com/p/simple-android-instant-messaging-application/source/browse/trunk/res/layout/messaging_screen.xml?r =6 ):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!--
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:text="Friend:"
/>
<EditText android:id="@+id/friendUserName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:singleLine="true"
android:editable="false" />
-->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:text="Messages:"/>
<EditText android:id="@+id/messageHistory"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:layout_weight="1"
android:editable="false"
android:gravity="top"
android:scrollbars="vertical"
android:scrollbarSize="10px"
/>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="4">
<EditText android:id="@+id/message"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top"
android:layout_weight="1"
/>
<Button android:id="@+id/sendMessageButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="4"
android:text="Send"/>
</LinearLayout>
</LinearLayout>
間違った方法で使用しているかどうかはわかりませんが、すべての受信メッセージは常に同じテキスト ビューに表示され、以前にあったメッセージが新しい受信メッセージで上書きされます。おそらく、JAVA 側のために何かをする必要があると思います。
言い換えれば、私が望むのは、メッセージがスクロール可能に見える場所であり、到着するすべての新しいメッセージが右側に次々と表示されることです。送信メッセージは左側に表示されます。もちろん、i-phone などの SMS アプリの外観についても話しています。
これを行う方法がわかりません。誰かが回避策、またはこれを実装する方法に関する情報を知っていれば、それは大歓迎です。