0

アプリケーションにチャットを実装する方法を探していました。着信メッセージと発信メッセージを取得する方法を既に実装しています。私の唯一の問題は、チャットのレイアウトを作成する方法です。しかし、私は本当にそれを理解することはできません。見てみると、チャットのようなレイアウトが見つかりました ( 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 アプリの外観についても話しています。

これを行う方法がわかりません。誰かが回避策、またはこれを実装する方法に関する情報を知っていれば、それは大歓迎です。

4

2 に答える 2

1

ListView個々のチャット メッセージ履歴をすべて表示する画面とEditText、ユーザーが新しいテキストを入力する画面を実装する必要があります。上部のタイトルや「送信」ボタンなど、さまざまなサポート UI 要素が存在する場合があります。

ListViewアイテムには、必要に応じて、メッセージだけでなく、日付スタンプやその他の情報も表示されます。着信メッセージと発信メッセージに異なる背景を使用できます。

の例を見つけてListView、そこから始めてください。

于 2013-03-22T23:32:09.987 に答える
0

必要なのはListView、メッセージを表示する です。どんなメッセージもあなたのアイテムになりますListView。コンテンツについては、Adapterメッセージのデータ構造を知っている を実装する必要があります。ListView 内の ListView、Adapter、およびカスタム ビューの良い例は、http: //www.ezzyearning.com/tutorial.aspx?tid=1763429 です。

于 2013-03-22T23:29:49.193 に答える