openfire+smack仿微信会话界面制作

在openfire服务器下制作的仿微信会话界面,包括接收用户的消息,初始化数据列表ListView,好友名称,好友头像,聊天消息,消息发送时间等,以及统计好友消息数目。

界面效果:

       

由于会话界面用到的是Fragment,于是想要实现自定义ListView利用到了ListFragment组件,直接让当前Fragment继承ListFragment类;然后就是Fragment的布局文件和item布局文件,将item整理成理想的样式;在Fragment中获取用户收到的好友消息,好友名,头像等,使用SimpleAdapter适配器进行数据适配;统计好友发送的消息数目,显示在UI上,已经点击item项触发事件,跳转聊天页面。

1、Fragment的布局文件fragment_one.xml,这里就仅仅是一个ListView,要注意的是ListView的id必须是Android:list,此为ListFragment指定的ListView项。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <ListView 
        android:id="@+id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </ListView>
</LinearLayout>

2、Fragment的item项布局文件fragment_one_item.xml,将所有的内容都放在一个相对布局中,头像和时间都单独放,将好友名和好友消息放置在一个垂直布局中,最后在加上红点文本,放置在最上端显示。

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="5dp"
    android:background="@drawable/linearlayout_boder">
	<LinearLayout 
	    android:layout_width="fill_parent"
	    android:layout_height="wrap_content"
	    android:layout_margin="5dp"
	    android:orientation="horizontal" >
	    <ImageView 
		    android:id="@+id/tab1_item_img"
		    android:layout_width="50dp"
		    android:layout_height="50dp"
		    android:layout_gravity="center_vertical"
	    />
	    <LinearLayout 
	        android:layout_width="0dp"
			android:layout_height="match_parent"
			android:layout_weig
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值