我正在使用通用图像加载器,我有一个ListView
,每行都有一个图像。快速向下滚动时,图像不会更新,并且会使用旧图像。但是,当慢慢向下滚动时,图像可以更新,但需要一些时间。这会让人觉得列表正在重复。
这些是我的选择:
options = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
.displayer(new FadeInBitmapDisplayer(0, true, false, false))
.build();
这就是我加载getView()
方法的方法:
ImageLoader.getInstance().displayImage(MY_IMAGE_URL+imageid, holder.imgView, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
holder.progressBar.setVisibility(View.VISIBLE);
holder.placeHolder.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
String message = null;
switch (failReason.getType()) {
case IO_ERROR:
message = "Input/Output error";
break;
case DECODING_ERROR:
message = "Image can't be decoded";
break;
case NETWORK_DENIED:
message = "Downloads are denied";
break;
case OUT_OF_MEMORY:
message = "Out Of Memory error";
break;
case UNKNOWN:
message = "Unknown error";
break;
}
//Toast.makeText(ImagePagerActivity.this, message, Toast.LENGTH_SHORT).show();
holder.progressBar.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
holder.progressBar.setVisibility(View.GONE);
holder.placeHolder.setVisibility(View.GONE);
}
});
如何确保在列表视图中正确加载图像?
答案 0 :(得分:0)
试试这个..
ImageLoader.getInstance().displayImage(MY_IMAGE_URL+imageid, holder.imgView, options);
在适配器中加载图片..
按如下方式更新DisplayImageOptions
options = new DisplayImageOptions.Builder()
.showImageOnLoading(android.R.color.transparent)
.showImageForEmptyUri(android.R.color.transparent)
.showImageOnFail(android.R.color.transparent)
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
显示并隐藏onPreExecute()
的{{1}}和onPostExecute()
内的进度条,该进度条由包含列表的片段/活动调用