Tushar Saha
Tushar Saha

Reputation: 63

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.

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. How to do that ? Thanks in advance.

Upvotes: 0

Views: 511

Answers (1)

Itai Hanski
Itai Hanski

Reputation: 8680

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. 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. 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.

Try using ImageLoader.get() with the width and height appropriate to the bigger view in the detail screen.

The other alternative is to load 2 versions of the same image.

Upvotes: 0

Related Questions