我有一个将图像从服务器加载到 ImageView 的列表视图。Listview 实现了 viewholder 模式,并有一个非常简单的行相对布局。对于延迟图像加载,我尝试了universalimageloader,picasso,目前正在使用基于google volley的glide,它应该非常快。但是:我的列表视图在用服务器图像替换占位符图像时仍然口吃,我不知道为什么,这是我的适配器代码:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
News newsItem = getItem(position);
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(mResource, null);
// Create a viewHolder enabled row
NewsViewHolder viewHolder = new NewsViewHolder();
viewHolder.newsTitle = (TextView) rowView.findViewById(R.id.news_title);
viewHolder.newsSubTitle = (TextView) rowView.findViewById(R.id.news_sub_title);
viewHolder.newsDescription = (TextView) rowView.findViewById(R.id.news_desc);
viewHolder.newsDate = (TextView) rowView.findViewById(R.id.news_date);
viewHolder.newsThumb = (ImageView) rowView.findViewById(R.id.news_thumb);
rowView.setTag(viewHolder);
}
NewsViewHolder holder = (NewsViewHolder) rowView.getTag();
// Fill in fields of the current row of the NewsListView
holder.newsTitle.setText(newsItem.title);
holder.newsSubTitle.setText(newsItem.subTitle);
holder.newsDescription.setText(newsItem.desciption);
holder.newsDate.setText(SimpleDateFormat.getDateInstance().format(new Date(Long.parseLong(newsItem.date) * 1000)));
Glide.load(newsItem.imageThumb)
.centerCrop()
.placeholder(R.drawable.placeholder)
.into(holder.newsThumb);
return rowView;
}
}
/*
* ViewHolder class for NewsListView
*/
public static class NewsViewHolder {
public TextView newsTitle;
public TextView newsSubTitle;
public TextView newsDescription;
public TextView newsDate;
public ImageView newsThumb;
}
该列表仅在我第一次滚动时出现口吃,因此当我的图像被检索并通过滑行粘贴到列表中时。将图像粘贴到列表视图中后,滚动就像从一开始就应该的那样光滑。
我做错了什么?如何有效地找出导致挂断的原因?我不是 Traceview 的专家,它会产生大量数据进行筛选。
谢谢你的帮助!