代码:
主布局******
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/listView_chat"
android:divider="#0000">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/layout"
android:orientation="horizontal"
>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/editText_chat"
android:hint="请在此输入内容"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/send_button"
android:text="发送"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
实体类******
public class Chat {
//定义内容和消息类型
String content;
int type;
int leftImageId;
int rightImageId;
//消息类型有两种