关于类微信时间戳的实现

本文介绍了如何实现类似微信的时间戳功能。当短时间内回复聊天内容时不显示时间戳,超过一定时间间隔则显示。通过布局文件(in.xml, out.xml)设置ListView,其中包含发送和接收的消息item。关键在于Adapter中判断时间,若当前输入与上一条消息间隔超过10秒,显示时间戳。在getViewTypeCount()中返回4,对应四种不同ViewType,在getItemViewType()中确定具体类型,以确保正确显示。" 124701255,10350762,微信小程序封装指示点组件,"['微信小程序', '前端开发']
摘要由CSDN通过智能技术生成

类为微信的时间戳的实现:

短期内回复聊天内容,则不会出现时间戳;长时间后回复,则出现时间戳。贴图如下:


大家如果对本人的应用感兴趣的话,可以去小米应用市场,或者豌豆荚下载“小黄鸡” , 认准开发者的账号:UstcLin


下面进入正题,如何实现时间戳。

说说我的主要思路。

首先layout一个文件,里边放置一个listview。同时还有两个xml,即发送出去的listitem和一个接收的listitem


in.xml 代码如下:

<?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="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/chat_from_createDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2012-09-01 18:30:20"
        style="@style/chat_date_style"
        android:visibility="gone"
       />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/chat_from_icon"
                android:layout_width="49dp"
                android:layout_height="49dp"
                android:src="@drawable/icon" />

            <TextView
                android:id="@+id/chat_from_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="小黄鸡"
                android:textSize="18sp" />
        </LinearLayout>
        
        <TextView 
            android:id="&#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值