首页 > 代码库 > ListView 关于减少耗时方法调用优化

ListView 关于减少耗时方法调用优化

private class GirdTemp {
TextView nameTV;
ImageView mGPUImageView;
Bitmap image;
}

 

===========================================================================================

final GirdTemp temp;

if (convertView == null) {
convertView = mInflater.inflate(R.layout.beautify_horizon_list_items, parent,false);
temp = new GirdTemp();
temp.nameTV= (TextView)convertView.findViewById(R.id.filter_name);
temp.mGPUImageView = (ImageView) convertView.findViewById(R.id.gpuimage);

convertView.setTag(temp);
} else {
temp = (GirdTemp) convertView.getTag();
}

if(temp.image == null){
temp.image = ActivityGallery.mGPUImage.getBitmapWithFilterApplied();
temp.mGPUImageView.setImageBitmap(temp.image);
temp.mGPUImageView.setTag(temp.image);
}else{
temp.mGPUImageView.setImageBitmap((Bitmap)temp.mGPUImageView.getTag());
}

 

这里:ActivityGallery.mGPUImage.getBitmapWithFilterApplied() 为耗时操作,因此优化方案是减少它的调用,采用 setTag getTag 重复利用它的结果

ListView 关于减少耗时方法调用优化