Java 图像缓存不在列表视图中

Java 图像缓存不在列表视图中,java,android,image,caching,Java,Android,Image,Caching,嗨,伙计们,我一直在使用图像缓存。我需要用网络上的图像填充线性布局 我在搜索如何在android中缓存图像的示例,发现了以下示例: 我尝试为我的代码实现它 String picPath = "https://www.google.lt/logos/classicplus.png"; try { /* View v = null;//new View(this); ImageLoader loader = new Imag

嗨,伙计们,我一直在使用图像缓存。我需要用网络上的图像填充线性布局

我在搜索如何在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进行图像缓存的示例。但是,如果我不使用列表视图,该怎么办呢

我会写我自己的缓存,但如何使回调图像下载,因为我想首先添加图像布局,并在回调更新它


谢谢

您必须在父视图上调用invalidate

    pubLayout.getParent().invalidate();

我应该什么时候打电话?我的PublyOut是线性布局,没有invalidate();只是invalidateChild(子对象,r)和invalidateChildInParent(位置,r)这听起来很奇怪。我的线性布局确实无效。\你正在使用哪个版本的Android…这不是我想要的,所以接受答案是错误的,因为其他人不会觉得它有用。我想我很感谢你的帮助。抱歉耽误了你的时间