[英]Image caching not in List View android
嗨,大家好,我一直不喜欢图像缓存。 我需要用来自网络的图像填充线性布局。
我正在搜索示例如何在android中缓存图像,并找到了以下示例:
我尝试将其实现为我的代码。
String picPath = "https://www.google.lt/logos/classicplus.png";
try {
/*
View v = null;//new View(this);
ImageLoader loader = new ImageLoader(this);
ImageView im = (ImageView)this.findViewById(R.id.image);
loader.DisplayImage(picPath, im);
addImage( im);*/
LayoutInflater inflater =(LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View convertView = inflater.inflate(R.layout.item, null);
ImageView image = (ImageView)convertView.findViewById(R.id.image);
ImageDownloader down = new ImageDownloader();
down.download(picPath, image);
addImage(image);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
public void addImage( View view){
LinearLayout pubLayout = (LinearLayout)findViewById( R.id.scrollerLinearlayout);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
//setting layout_margin
params.setMargins(15, 30, 15, 30);
pubLayout.addView(view,params);
}
但是,这没有用。 我相信,因为我将视图添加到线性布局,并且在下载图像时无法重绘它?
有示例如何使用ListView进行图像缓存。 但是,如果我不使用列表视图怎么办。
我会编写自己的缓存,但是如何对下载的图像进行回调,因为我想先将图像添加到布局并在回调时对其进行更新?
谢谢。
您必须在父视图上调用无效
pubLayout.getParent().invalidate();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.