该楼层疑似违规已被系统折叠隐藏此楼查看此楼
-接上-
众所周知,listview要充分运用到缓存试图convertView,否则一旦数据量大了很容易造成OOM异常,而我们的adaper里有用到两种视图布局,又该如何去重复利用呢?
乾坤在这里:public int getItemViewType(int position) {
// TODO Auto-generated method stub
ChatMsgEntity entity = coll.get(position);
if (entity.getMsgType())
{
return IMsgViewType.IMVT_COM_MSG;
}else{
return IMsgViewType.IMVT_TO_MSG;
}
}
public int getViewTypeCount() {
// TODO Auto-generated method stub
return 2;
}
getItemViewType用来识别视图类型getViewTypeCount标识视图类型数量这样每次缓存下来的视图就总是能传递正确的对象去重复利用了
最后再贴一个item的布局出来:<?xml version="1.0" encoding="utf-8"?>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="6dp">
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">
android:id="@+id/tv_sendtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/chat_text_date_style"/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
android:id="@+id/iv_userhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/mini_avatar_shadow"/>
android:id="@+id/tv_chatcontent"
android:layout_toRightOf="@id/iv_userhead"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/chatfrom_bg"
style="@style/chat_content_date_style"/>
android:id="@+id/tv_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/iv_userhead"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/tv_chatcontent"
style="@style/chat_text_name_style"/>
(完)
来源:
android 仿微信聊天气泡显示图片 eoe资源:仿微信聊天气泡界面的实现(dota小黑与大马的对白)...