我正在使用Glide Image Loader。 从服务器加载图像需要太长时间(超过200秒) 在某些情况下不加载。 所有图像都存储在云服务器上。
当我向后滚动到顶部时,图像就像第一次显示一样,显示需要一点时间,图像缓存也无法正常工作 在像亚马逊这样的应用程序中,Facebook一次性加载的图像并没有消失。我想在我的应用程序上使用相同的技术。
我使用DynamicheightImageview使用Staggered Gridview,为此我在onBindViewHolder上调用AsyncTask
new GetImageTask(singleArtDataitem, vh.imageView, position).execute(singleArtDataitem);
的AsyncTask
private class GetImageTask extends AsyncTask<SingleArtData, Void, Float> {
private SingleArtData item;
private final DynamicHeightImageView imageView;
int position;
public GetImageTask(SingleArtData item, DynamicHeightImageView holder, int position) {
this.imageView = holder;
this.position = position;
}
@Override
protected Float doInBackground(SingleArtData... params) {
item = params[0];
try {
if (GlobalMethods.isNotEmpty(item.getImageName())) {
item.setImagefullurl(baseuri + item.getImageName());
URL neturl = new URL(item.getImagefullurl());
final Bitmap image = BitmapFactory.decodeStream(neturl.openConnection().getInputStream());
int width = image.getWidth();
int height = image.getHeight();
item.setImage_width(width);
item.setImage_height(height);
float ratio = (float) height / (float) width;
item.setImage_ratio(ratio);
} else {
item.setImagefullurl(null);
}
} catch (Exception e) {
item.setImagefullurl(null);
e.printStackTrace();
}
return item.getImage_ratio();
}
@Override
protected void onPostExecute(Float result) {
RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
rlp.height = (int) (rlp.width * result);
imageView.setLayoutParams(rlp);
imageView.setHeightRatio(result);
if (GlobalMethods.isNotEmpty(item.getImagefullurl())) {
// Picasso.with(mContext)
// .load(baseuri + item.getImageName()).placeholder(PlaceHolderDrawableHelper.getBackgroundDrawable(position))
// .error(R.drawable.ic_med)
// .into(imageView);
Glide.with(MyApplication.getInstance())
.load(item.getImagefullurl()).placeholder(PlaceHolderDrawableHelper.getBackgroundDrawable(position))
.error(R.drawable.loadicon)
.placeholder(PlaceHolderDrawableHelper.getBackgroundDrawable(position))
.diskCacheStrategy(DiskCacheStrategy.ALL)
.skipMemoryCache(false)
.into(imageView);
}
}
}
提前致谢。