【问题标题】:how to download images over http to android cache and display later?如何通过 http 将图像下载到 android 缓存并稍后显示?
【发布时间】:2014-06-10 16:07:09
【问题描述】:

我是 android 新手,我在这里有一个场景。我有一个显示项目列表的应用程序,单击每个列表项会打开一个显示图像和其他一些细节的活动。我制作了这个应用程序,使它可以离线工作。

但在图像的情况下,我使用了 Android 通用图像加载器库,但为此我看到方法 loadImagedisplayImage 需要绑定到 UI 元素。我希望应用程序在有网络时下载所有图像,然后当我在离线模式下打开任何ListView 项目时,我希望从cache 中选择图像并显示。

你们中的任何人都可以提出一种我可以实现这一目标的方法吗?在一个类似的查询中,我遇到了 android executorService。我应该应用这个吗?

提前致谢。

【问题讨论】:

标签: android caching universal-image-loader


【解决方案1】:

http://code.google.com/p/android-query/wiki/ImageLoading

aq.id(R.id.image1).image(imageUrl, true, true);

如果为 true,则为 memoryCache 和 fileCache。

【讨论】:

  • 谢谢,我会检查一下。但看起来我必须在这里提供资源 ID。在我的情况下,我有多个动态添加的项目,所以我不确定资源 ID。另外,我正在寻找可以将所有图像下载到缓存中的东西,然后我只能在打开屏幕时才能访问它们。
  • 你也可以将它指向 ImageView 对象。检查我给你的链接有很多关于它的信息。
  • 我使用了 aQuery 的Prefetch 功能。达到了我想要的。谢谢@JakubW
【解决方案2】:

您可以使用通用图像加载器下载位图,这是代码的一部分,

imageLoader.displayImage(profilePic, profileImage, options,
                            new ImageLoadingListener() {
                                @Override
                                public void onLoadingComplete(String imageUri,
                                        View view, Bitmap loadedImage) {
                                    // loadedImage - is the downladed bitmap, you can use this for  your further implementation.
                                }

                                @Override
                                public void onLoadingStarted(String imageUri,
                                        View view) {
                                    // TODO Auto-generated method stub

                                }

                                @Override
                                public void onLoadingFailed(String imageUri,
                                        View view, FailReason failReason) {
                                    // TODO Auto-generated method stub

                                }

                                @Override
                                public void onLoadingCancelled(String imageUri,
                                        View view) {
                                    // TODO Auto-generated method stub

                                }
                            });

【讨论】:

  • 感谢@Aerrow,在您的示例中,我必须指定要在其中显示图像的 imageView。但就我而言,我希望先下载所有图像,然后在启动该视图时将图像设置为 imageView。
猜你喜欢
  • 2019-02-08
  • 2012-11-16
  • 2011-06-29
  • 2016-10-25
  • 1970-01-01
  • 2014-09-02
  • 2014-12-11
  • 1970-01-01
  • 2013-05-22
相关资源
最近更新 更多