首先看看效果:

实现方式还是listview自定义adapter,只不过用了两个布局文件,左边的一种布局,右边的一种布局,在消息实体类中添加一个变量,用来判断是发出的消息还是收到的消息,从而在adapter的getView()中,决定采用哪种布局。
chat_listview_item_left.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/avatar_chat_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="https://blog.csdn.net/@drawable/avatar_default" /

本文介绍如何在Android开发中创建一个即时聊天工具YQ的气泡聊天功能。通过使用listview自定义adapter,利用两个不同的布局文件(chat_listview_item_left.xml和chat_listview_item_right.xml)来区分发送和接收的消息。在消息实体类中增加一个字段标识消息类型,根据该字段在adapter的getView()方法中动态选择显示布局。
1172

被折叠的 条评论
为什么被折叠?



