没有本地缓存​​(采用通用图像装载机)图片 - 慢图像加载时间 [英] Images not being cached locally (using Universal Image Loader) - slow image load times

查看:146
本文介绍了没有本地缓存​​(采用通用图像装载机)图片 - 慢图像加载时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题描述: 我创建的文章与上人口由我SQLite数据库缩略图的滚动列表。在一般情况下,它的工作,除了正在缓慢:

图像加载速度很慢...我想用通用图像装载机缓存在设备上的图像,这将让他们看起来只是滚动到视图,如果你已经看到他们(或至少接近)。但是 - 当向上/向下拖动,没有任何图像都在那里,然后3-5秒钟之后,图像开始弹出中(就好像它是重新下载它们)

我改变了对飞缩略图框的知名度,但毕竟是工作完美无缺 - 它们似乎并没有改变 - 他们只是滚动到视图与否,无闪烁或任何东西。 (但随后的图像不会出现,几秒钟)。

我通过滚动左右......当我向后滚动$ P $光伏点后,除去我的PHP脚本测试,图像显示不出来 - 让我以为它加载从我的PHP脚本,每次<。 / P>

但是,根据的文档UsingFreqLimitedMemoryCache(最不频繁当超出缓存大小限制使用位图被删除) - 默认情况下使用

详细信息:

在我的 ArticleEntryAdapter.js 我:

  @覆盖
公共查看getView(最终诠释的位置,最后查看convertView,最终的ViewGroup父){

    //我们需要以获得最佳的视图(重新使用如果可能的话),然后
    //获取其相应ViewHolder,优化查找效率
    最终的视图中查看= getWorkingView(convertView);
    最后ViewHolder viewHolder = getViewHolder(视图);
    最后一篇文章的文章=的getItem(位置);

    //设置标题
    viewHolder.titleView.setText(article.title);

    //设置字幕(小标题)或描述
    如果(article.subtitle!= NULL)
    {
        viewHolder.subTitleView.setText(article.subtitle);
    }
    否则,如果(article.description!= NULL)
    {
        viewHolder.subTitleView.setText(article.description);
    }

    ImageLoader的ImageLoader的= ImageLoader.getInstance();

    imageLoader.displayImage(,viewHolder.thumbView); //清除previous 1
    如果(article.filepath =空&安培;!&安培;!article.filepath.length()= 0){
        imageLoader.displayImage(
            http://img.sltdb.com/processes/resize.php?image=+ article.filepath +&放大器;大小= 100安培;质量= 70,
            viewHolder.thumbView
            );
        viewHolder.thumbView.setVisibility(View.VISIBLE);
    } 其他 {
        viewHolder.thumbView.setVisibility(View.GONE);
    }

    返回查看;
}
 

至于图像是不正确 - 这不是经常,但有时滚动时,我会看到相同的图像2,当我看的文章,他们不是在所有相关的(即无机会实际上具有相同的图像)所以 - 我从中滚动走了,回,它不再是不正确的图像

注:我是新来的Java / Android的 - 你可能已经注意到了

更多$ C $每次评论请求C:

 私人查看getWorkingView(最终查看convertView){
    //该workingView基本上只是convertView再使用,如果可能的
    //或夸大新如果没有可能
    查看workingView = NULL;

    如果(空== convertView){
        最终的上下文语境=的getContext();
        最后LayoutInflater充气=(LayoutInflater)context.getSystemService
          (Context.LAYOUT_INFLATER_SERVICE);

        workingView = inflater.inflate(articleItemLayoutResource,NULL);
    } 其他 {
        workingView = convertView;
    }

    返回workingView;
}
 

更新: 我的清单文件有:

 &LT;使用-权限的Andr​​oid:名称=android.permission.WRITE_EXTERNAL_STORAG​​E/&GT;
 

但我发现缓存文件夹完全是空的:

  MNT
  -SD卡
    -Android
      -数据
        -com.mysite.news
          -cache
            -uil,图像
 

解决方案

我遇到了类似的问题,在列表视图图像。也许这个答案会纠正你的错误的形象问题。

我刚刚下载与UniversalImageLoader示例项目,并表现出你所描述的相同的行为。

的几点说明到目前为止,从翻翻源$ C ​​$ C。

 公共静态最终诠释DEFAULT_THREAD_POOL_SIZE = 3;
公共静态最终诠释DEFAULT_THREAD_PRIORITY = Thread.NORM_PRIORITY  -  1;
公共静态最终诠释DEFAULT_MEMORY_CACHE_SIZE = 2 * 1024 * 1024; //字节
 

这表示,在任何时候都会有三个线程下载的最大2MB图像的和。到底有多大,你正在下载的图片吗?此外,你缓存到磁盘?如果是这样,这将是缓慢的。

要配置一些在ImageLoader的基本选项,你将需要传递到displayImage:

  DisplayImageOptions选项=新DisplayImageOptions.Builder()
     .showStubImage(R.drawable.stub_image)
     .cacheInMemory()
     .cacheOnDisc()
     。建立();
 

我也想你尝试以下几种:

  ImageLoaderConfiguration imageLoaderConfiguration =新ImageLoaderConfiguration.Builder(本)
    .enableLogging()
    .memoryCacheSize(41943040)
    .discCacheSize(104857600)
    .threadPoolSize(10)
    。建立();

ImageLoader的= ImageLoader.getInstance();
imageLoader.init(imageLoaderConfiguration);
 

通过我的测试中,该图像是磁盘上,但负荷仍然缓慢。

经过广泛的测试,我确定的主要问题是UniversalImageLoader仅仅是缓慢的。具体来说,ImageLoader的和LoadAndDisplayImageTask持有赶工。我(非常快)改写了LoadAndDisplayImageTask作为一个AsyncTask的,它立即表现较好。你可以下载的GitHub上的code中的分叉版本。

通用与图像装载机AsyncTasks

Description of the problem: I'm creating a scrollable list of articles with thumbnails that's populated by my SQLite database. In general, it's "working" except being slow:

The images load very slowly... I thought using the "Universal Image Loader" cached the images on the device, and that that would make them appear to just scroll into view if you'd already viewed them (or at least close to that). But - when you drag up/down, none of the images are there, then 3-5 seconds later, the images start popping in (as though it's re-downloading them)

I'm changing the visibility of the thumbnail boxes on the fly, but that is working flawlessly - they don't appear to change - they just scroll into view or not, no flashing or anything. (but then the images don't appear for another few seconds).

I've tested by removing my php script after scrolling around... when I scroll back to prev spot, the images don't show up - making me assume it's loading from my PHP script EVERY time.

But according to the docs: "UsingFreqLimitedMemoryCache (The least frequently used bitmap is deleted when cache size limit is exceeded) - Used by default"

Details:

In my ArticleEntryAdapter.js I have:

@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {

    // We need to get the best view (re-used if possible) and then
    // retrieve its corresponding ViewHolder, which optimizes lookup efficiency
    final View view = getWorkingView(convertView);
    final ViewHolder viewHolder = getViewHolder(view);
    final Article article = getItem(position);

    // Set the title
    viewHolder.titleView.setText(article.title);

    //Set the subtitle (subhead) or description
    if(article.subtitle != null)
    {
        viewHolder.subTitleView.setText(article.subtitle);
    }
    else if(article.description != null)
    {
        viewHolder.subTitleView.setText(article.description);
    }

    ImageLoader imageLoader = ImageLoader.getInstance();

    imageLoader.displayImage("", viewHolder.thumbView); //clears previous one
    if(article.filepath != null && article.filepath.length() != 0) {
        imageLoader.displayImage(
            "http://img.sltdb.com/processes/resize.php?image=" + article.filepath + "&size=100&quality=70",
            viewHolder.thumbView
            );
        viewHolder.thumbView.setVisibility(View.VISIBLE);
    } else {
        viewHolder.thumbView.setVisibility(View.GONE);
    }

    return view;
}

As far as the images being incorrect - it's not often, but sometimes while scrolling, I'll see 2 of the same image, and when I look at the articles, they're not at all related (ie no chance of actually having the same image) So - I scroll away from it, and back, and it's no longer the incorrect image.

NOTE: I'm new to Java/Android - you probably already noticed that.

More code per comment-request:

private View getWorkingView(final View convertView) {
    // The workingView is basically just the convertView re-used if possible
    // or inflated new if not possible
    View workingView = null;

    if(null == convertView) {
        final Context context = getContext();
        final LayoutInflater inflater = (LayoutInflater)context.getSystemService
          (Context.LAYOUT_INFLATER_SERVICE);

        workingView = inflater.inflate(articleItemLayoutResource, null);
    } else {
        workingView = convertView;
    }

    return workingView;
}

UPDATE: My Manifest file has:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

But the cache folder I found is completely empty:

mnt
  -sdcard
    -Android
      -data
        -com.mysite.news
          -cache
            -uil-images

解决方案

I was experiencing similar issues with images in list view. Possibly this answer will correct your wrong image problem.

I just downloaded the sample project with UniversalImageLoader and it exhibits the same behavior you are describing.

A few notes so far from looking through the source code.

public static final int DEFAULT_THREAD_POOL_SIZE = 3;
public static final int DEFAULT_THREAD_PRIORITY = Thread.NORM_PRIORITY - 1;
public static final int DEFAULT_MEMORY_CACHE_SIZE = 2 * 1024 * 1024; // bytes

This says that at any time there will be three threads downloading and max of 2MB of images. How big are the images you are downloading? Also are you caching to disk? If so, that will be slow.

To configure some of the basic options in the ImageLoader you will need to pass in to displayImage:

 DisplayImageOptions options = new DisplayImageOptions.Builder()
     .showStubImage(R.drawable.stub_image)
     .cacheInMemory()
     .cacheOnDisc()
     .build();

I would also like you to try these options:

ImageLoaderConfiguration imageLoaderConfiguration = new ImageLoaderConfiguration.Builder(this)
    .enableLogging()
    .memoryCacheSize(41943040)
    .discCacheSize(104857600)
    .threadPoolSize(10)
    .build();

imageLoader = ImageLoader.getInstance();
imageLoader.init(imageLoaderConfiguration);

With my testing, the images are on disk, but loading is still slow.

After extensive testing, I determined the primary issue is that UniversalImageLoader is just slow. Specifically, the ImageLoader and LoadAndDisplayImageTask are holding up the works. I (very quickly) rewrote the LoadAndDisplayImageTask as an AsyncTask and it immediately performed better. You can download the forked version of the code on GitHub.

Universal Image Loader with AsyncTasks

这篇关于没有本地缓存​​(采用通用图像装载机)图片 - 慢图像加载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆