关于聊天内容,见得多了,就是一个列表,里面存着不同的人的聊天记录,自己的内容在一边,其它人的内容在另一边。列表没有看到分隔线,背景是白的或其它的,没有列表按下的效果。
现在一个一个解决:
列表背景android:background="" android:cacheColorHint=""
这两个颜色设置成一样的,就可以了。
如果选中的颜色也不要,可以自定义一个selector,设置成固定 的颜色 android:listSelector="#00000000" 这样。
android:dividerHeight="0.0dip" 设置分隔线的高度为0,但是还可以看到一个分隔线。
还需要一个设置android:divider="@null"就可以完全移除分隔线了。
内容显示在左与右,最蠢的办法就是:
if (orientation==1) {
((LayoutInflater) mContext.getSystemService("layout_inflater")).inflate(R.layout.chat_left_item, this);
chat_txt_time=(TextView) findViewById(R.id.chat_txt_time);
chat_txt_msg=(TextView) findViewById(R.id.chat_txt_msg);
//content=(LinearLayout) findViewById(R.id.content);
nickname=(TextView) findViewById(R.id.chat_name);
} else {
((LayoutInflater) mContext.getSystemService("layout_inflater")).inflate(R.layout.chat_right_item, this);
chat_txt_time=(TextView) findViewById(R.id.chat_txt_time);
chat_txt_msg=(TextView) findViewById(R.id.chat_txt_msg);
//content=(LinearLayout) findViewById(R.id.content);
nickname=(TextView) findViewById(R.id.chat_name);
}
弄两个布局了,就可以解决了,但性能不高。
可以动态的处理View元素的位置,比如一个ImageView作头像,一个TextView作文本,使用relativelayout,使用java动态的处理它们间的关系,也是可以的。relativelayout addRule可以添加规则,动态的添加子元素,这样至少不必每次都新建一个Layout,可以重复使用原来的。
而上面的加载不同的布局,是不可以重用的,每次需要重新加载新的。
android聊天列表实现
最新推荐文章于 2023-10-15 20:46:01 发布