类为微信的时间戳的实现:
短期内回复聊天内容,则不会出现时间戳;长时间后回复,则出现时间戳。贴图如下:
大家如果对本人的应用感兴趣的话,可以去小米应用市场,或者豌豆荚下载“小黄鸡” , 认准开发者的账号: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="&#