我想创建一个聊天活动,其中用户可以发送和接收消息。发送者消息在右边气泡中带有时间戳,接收消息在左边气泡中有时间戳。
到目前为止,我所做的是,我已经创建了一个聊天应用程序,它工作正常,我的消息在右边,收到消息在左边,但我不知道如何添加时间戳气泡就像whatsapp。
请帮助我,这对我很重要。
发布于 2015-01-08 18:20:50
使用以下代码获取当前时间:
 DateFormat df = new SimpleDateFormat("HH:mm");
 Calendar calobj = Calendar.getInstance();
 System.out.println(df.format(calobj.getTime()));发布于 2015-07-04 00:57:27
有点晚了,但也许还是有人需要它。请考虑在下面的场景中,我以编程方式设置了gravity和textAlignment,这取决于气泡的位置,左边还是右边。这就是我是如何做到的:
普通视图

布局边界已启用

XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/chat_wrapper"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
  <RelativeLayout
      android:id="@+id/message_wrapper"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginTop="10dip">
    <TextView
        android:id="@+id/message_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="100dip"
        android:paddingBottom="5dip"
        android:textColor="#000000"/>
    <TextView
        android:id="@+id/message_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/message_text"
        android:layout_below="@+id/message_text"
        android:textColor="#000000"
        android:textSize="9sp"/>
  </RelativeLayout>
</LinearLayout>其他信息
背景是我以编程方式设置的9补丁图像,可以通过简单的搜索找到。测试对象:
三星Galaxy
发布于 2015-07-04 06:31:08
我已经从androidhive链接下载了代码,您必须更改以下两个布局文件
list_item_message_right.xml. 
list_item_message_left.xml.在上述布局文件中为时间戳添加一个新的文本视图,然后在MessageListAdapter类中设置它们的值时间戳值
    lblFrom.setText(m.getFromName());
//set time stamp herehttps://stackoverflow.com/questions/27837692
复制相似问题