谁真正解决过 android listview滑动时效率慢的问题?
最近做我们的产品 有100多个联系人 显示在UI时,滑动效率很慢,比较卡,观察了下QQ通讯录,它的滑动非常顺,一点也不卡。
以下是我getView的代码,红色标实的是绑定一个联系人名字,不注释的话,滑动非常卡,注释的话,就滑动非常顺。
final ContactItem conItem = contactArrayList.get(position);
if (convertView == null) {
convertView = mLayoutInflater.inflate(mItemLayout, null);
holder = new ViewHolder();
holder.enterLayout = (LinearLayout) convertView.findViewById(R.id.layout_enter);
holder.HintTextView = (TextView) convertView.findViewById(R.id.text_first_char_hint);
holder.title = (TextView) convertView.findViewById(R.id.content);
holder.laytH = (LinearLayout) convertView.findViewById(R.id.layout1);
holder.leftIcon = (ImageView) convertView.findViewById(R.id.phonecall_detail_image);
holder.ivYouxinClient = (ImageButton) convertView.findViewById(R.id.ivYouxinClient);
holder.callLayout = (LinearLayout) convertView.findViewById(R.id.layout_call);
convertView.setVerticalScrollBarEnabled(true);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
//holder.title.setText(conItem.ctName);
最近做我们的产品 有100多个联系人 显示在UI时,滑动效率很慢,比较卡,观察了下QQ通讯录,它的滑动非常顺,一点也不卡。
以下是我getView的代码,红色标实的是绑定一个联系人名字,不注释的话,滑动非常卡,注释的话,就滑动非常顺。
final ContactItem conItem = contactArrayList.get(position);
if (convertView == null) {
convertView = mLayoutInflater.inflate(mItemLayout, null);
holder = new ViewHolder();
holder.enterLayout = (LinearLayout) convertView.findViewById(R.id.layout_enter);
holder.HintTextView = (TextView) convertView.findViewById(R.id.text_first_char_hint);
holder.title = (TextView) convertView.findViewById(R.id.content);
holder.laytH = (LinearLayout) convertView.findViewById(R.id.layout1);
holder.leftIcon = (ImageView) convertView.findViewById(R.id.phonecall_detail_image);
holder.ivYouxinClient = (ImageButton) convertView.findViewById(R.id.ivYouxinClient);
holder.callLayout = (LinearLayout) convertView.findViewById(R.id.layout_call);
convertView.setVerticalScrollBarEnabled(true);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
//holder.title.setText(conItem.ctName);
解决方案 »
- 好难过,界面倒是可以自己花时间布局起来,但是java代码都写不出!怎么办?放弃吗
- android库文件编译出错求,有Android源代码编译环境的大神帮忙编译一下java库文件,
- 怎把java代码变成android代码
- android 如何设定坐标,让程序自动点击。
- ubuntu android开发环境的搭建
- 求助:我使用gpio_export函数为什么没有/sys/class/gpio目录?
- 关于New一个对象的问题!!??
- 求教 如何在手机实体机中操作DDMS
- android 菜鸟问题
- 如何下载com.android.calendar所用到的lib, jar
- [Android 界面] PNG图片的透明部分不显示LAYOUT的背景色,怎么解决
- 求助,本人做一个视频监控的系统。想实现手指放大缩小视频的功能
如果字符串不慢,是否字符串长短之类的。实在不行就别用conItem了,起码用map方式肯定不慢,这个试过180个号码,也没出现过卡。
http://univasity.iteye.com/blog/1105619
这个可以参考一下,希望对你有用
========================================从上面的代码来看,你会每次getview时都会去findViewById,调用了很多次,说明你的这个复合view的布局还是比较复杂的。我觉得的性能是慢在这里。因为android 去inflate和findViewById,inflate它会解析结构层次并创建很多对象,而findViewById会在类层次中去查找某一个view(可能它内部有算法可以保证效率)我之前也遇到过比你更复杂的布局(listview里面放的是gallery),但都没有什么效率问题,我的解决方法是:完全重绘制,
像你这种情况,可以直接写一个view,它直接从view继承过来,绘制所有的元素。
这种方法可能有点复杂,但不是难。public class MyView extends View
{
public void setContactData(ContactItem item)
{
...
}
}
这是这么一种方式,把数据设置到自定义的view中去,由它绘制出来。
如下代码:
conItem.cDrawable = asyncImageLoader.loadDrawable(mContext, conItem.ctId,
holder.leftIcon, 0, new ImageCallback() {
@Override
public void imageLoaded(Drawable imageDrawable,
ImageView imageView, String imageUrl) {
imageView.setImageDrawable(imageDrawable);
} });因为每滑动一个item 都会去异步加载一次头像,不管有没有都去加载,造成卡的问题。因为是维护别人的代码,刚开始没找到,不好意思,误导大家了。
如下代码:
conItem.cDrawable = asyncImageLoader.loadDrawable(mContext, conItem.ctId,
holder.leftIcon, 0, new ImageCallback() {
@Override
public void imageLoaded(Drawable imageDrawable,
ImageView imageView, String imageUrl) {
imageView.setImageDrawable(imageDrawable);
}});因为每滑动一个item 都会去异步加载一次头像,不管有没有都去加载,造成卡的问题。因为是维护别人的代码,刚开始没找到,不好意思,误导大家了。那楼主是怎么解决的呢?