LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

Android 开发即时聊天工具 YQ :(七) 气泡聊天

admin
2013年2月25日 14:27 本文热度 3686

首先看看效果:



实现方式还是listview自定义adapter,只不过用了两个布局文件,左边的一种布局,右边的一种布局,在消息实体类中添加一个变量,用来判断是发出的消息还是收到的消息,从而在adapter的getView()中,决定采用哪种布局。


chat_listview_item_left.xml

[html]
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="wrap_content"  
  4.     android:layout_height="wrap_content" >  
  5.     <ImageView  
  6.         android:id="@+id/avatar_chat_left"  
  7.         android:layout_width="wrap_content"  
  8.         android:layout_height="wrap_content"  
  9.         android:src="@drawable/avatar_default" />  
  10.     <RelativeLayout   
  11.         android:id="@+id/rl_chat_left"  
  12.         android:layout_width="wrap_content"  
  13.         android:layout_height="wrap_content"  
  14.         android:layout_toRightOf="@id/avatar_chat_left"  
  15.         android:background="@drawable/chat_left">  
  16.     <TextView  
  17.         android:id="@+id/message_chat_left"  
  18.         android:layout_width="wrap_content"  
  19.         android:layout_height="wrap_content"  
  20.         android:maxWidth="160dip"/>  
  21.     </RelativeLayout>  
  22.     <TextView  
  23.         android:id="@+id/sendtime_chat_left"  
  24.         android:layout_width="wrap_content"  
  25.         android:layout_height="wrap_content"  
  26.         android:layout_toRightOf="@id/avatar_chat_left"  
  27.         android:layout_below="@id/rl_chat_left"  
  28.         android:textSize="10sp" />  
  29. </RelativeLayout>  

chat_listview_item_right.xml

[html]
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="wrap_content"  
  4.     android:layout_height="wrap_content" >  
  5.     <ImageView  
  6.         android:id="@+id/avatar_chat_right"  
  7.         android:layout_width="wrap_content"  
  8.         android:layout_height="wrap_content"  
  9.         android:layout_alignParentRight="true"  
  10.         android:layout_alignParentTop="true"  
  11.         android:src="@drawable/avatar_default" />  
  12.     <RelativeLayout  
  13.         android:id="@+id/rl_chat_right"  
  14.         android:layout_width="wrap_content"  
  15.         android:layout_height="wrap_content"  
  16.         android:layout_toLeftOf="@+id/avatar_chat_right"  
  17.         android:background="@drawable/chat_right" >  
  18.     <TextView  
  19.         android:id="@+id/message_chat_right"  
  20.         android:layout_width="wrap_content"  
  21.         android:layout_height="wrap_content"  
  22.         android:maxWidth="160dip" />  
  23.     </RelativeLayout>  
  24.     <TextView  
  25.         android:id="@+id/sendtime_chat_right"  
  26.         android:layout_width="wrap_content"  
  27.         android:layout_height="wrap_content"  
  28.         android:layout_below="@id/rl_chat_right"  
  29.         android:layout_toLeftOf="@+id/avatar_chat_right"  
  30.         android:textSize="10sp"/>  
  31. </RelativeLayout>  



在adapter中判断消息是发出的还是收到的:

[java]
  1. if(ce.isLeft()){  
  2.     convertView = inflater.inflate(R.layout.chat_listview_item_left, null);  
  3.       
  4. }else{  
  5.     convertView=inflater.inflate(R.layout.chat_listview_item_right, null);  
  6.   
  7. }  


别的都和以前的差不多,知道了原理其实挺简单的。

 


该文章在 2013/2/25 14:27:24 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved