相关疑难解决方法(0)

ListView中的图像延迟加载

我使用a ListView来显示与这些图像相关的一些图像和标题.我从互联网上获取图像.有没有办法延迟加载图像,以便文本显示时,UI不会被锁定,图像会在下载时显示?

图像总数不固定.

url android listview image universal-image-loader

1881
推荐指数
31
解决办法
54万
查看次数

Android:帮助使用ImageLoader类(LazyList)调整ListView适配器

我有一个自定义ListView适配器,它实现了ImageThreadLoader类.不幸的是,该类没有启用缓存选项 - 从Web下载图像并将其保存为缓存.

然后我发现这个LazyList或者这里非常有用,它的行为与我的ImageThreadLoader类完全相同,但它能够将图像保存为缓存.所以,我想将其ImageLoader类实现到我当前的自定义ListView适配器.

不幸的是,我的代码和Lazylist的结构完全不同,导致我的尝试出现了一些冲突.例如,LazyList使用图像URL的字符串数组,另一方面我使用JSON作为图像URL的源.

这就是为什么我需要一个帮助来使我的ListView适配器适应这个ImageLoader类.

以下是代码:

ImageLoader类,我希望实现到我的自定义ListView适配器:

public class ImageLoader {

    //the simplest in-memory cache implementation. This should be replaced with something like SoftReference or BitmapOptions.inPurgeable(since 1.6)
    private HashMap<String, Bitmap> cache=new HashMap<String, Bitmap>();

    private File cacheDir;

    public ImageLoader(Context context){
        //Make the background thead low priority. This way it will not affect the UI performance
        photoLoaderThread.setPriority(Thread.NORM_PRIORITY-1);

        //Find the dir to save cached images
        if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
            cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"Android/data/LazyList");
        else
            cacheDir=context.getCacheDir();
        if(!cacheDir.exists())
            cacheDir.mkdirs();
    }

    final int stub_id=R.drawable.stub;
    public …
Run Code Online (Sandbox Code Playgroud)

android

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×2

image ×1

listview ×1

universal-image-loader ×1

url ×1