简体   繁体   English

带有图像缓存的Android Volley

[英]Android Volley with Image Caching

Currently I'm working with an application where one activity holds a list view with image and text for each row. 目前,我正在使用一个应用程序,其中一个活动持有一个列表视图,其中每一行都有图像和文本。 I'm downloading the images using the volley. 我正在使用凌空下载图像。 When the list view item is clicked the app will switch to a another activity with a detail view where a large version of the clicked image will show. 单击列表视图项后,应用程序将切换到另一个活动,该活动带有详细信息视图,其中将显示较大版本的单击的图像。 For the both time I'm using NetworkImageView. 两次我都使用NetworkImageView。

Images are loaded in the list view with caching. 图像通过缓存加载到列表视图中。 But the problem appeared on the detailed view. 但是问题出现在详细视图上。 The images are showing from the previously loaded cache with low resolution. 图像是从先前加载的低分辨率缓存中显示的。 I want to load a good resolution image on detailed view which will cache the image separately for large view. 我想在详细视图上加载高分辨率图像,这将为大视图单独缓存图像。

For the both screen image url are same. 对于两个屏幕图像,URL都是相同的。 How to do that ? 怎么做 ? Thanks in advance. 提前致谢。

First thing is a bit obvious - make sure you images are at the wanted quality. 第一件事很明显-确保您的图像达到所需的质量。

If that's the case, you'll probably want to load the image "manually" using the ImageLoader class, as the NetworkImageView by default, optimizes the size of the Bitmap it creates to be the size of the view itself. 如果是这种情况,您可能需要使用ImageLoader类“手动”加载图像,因为默认情况下NetworkImageView会将其创建的Bitmap的大小优化为视图本身的大小。 So what happens is, you first load the thumbnail view which is small, and the saved Bitmap is created in that size instead of the original image size. 因此,发生的事情是,首先加载很小的缩略图视图,然后以该尺寸而不是原始图像尺寸创建保存的Bitmap Then, when the bigger view requests the same image, the cached version is returned which is a small Bitmap , and the view scales it up, creating the low-res appearance. 然后,当较大的视图请求相同的图像时,将返回缓存的版本,该版本是一个小的Bitmap ,并且该视图将其放大,从而创建了低分辨率的外观。

Try using ImageLoader.get() with the width and height appropriate to the bigger view in the detail screen. 尝试使用ImageLoader.get() ,使其宽度和高度适合于详细信息屏幕中的较大视图。

The other alternative is to load 2 versions of the same image. 另一种选择是加载同一图像的2个版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM