Muhammad Hewedy
Muhammad Hewedy

Reputation: 30068

How to user Android-Volley to set animated image until the image loads

In android volley, I know there's an attribute called mDefaultImageId in the NetwrokImageView. But this only displays "Default" still images.

I need to show either an animated image or a progress bar.

I know I can accomplish this if I use RequestQueue, but still I need to take advantages of ImageLoader.

How to accomplish that?

Thanks.

Upvotes: 2

Views: 3706

Answers (3)

Sushil
Sushil

Reputation: 41

if you are using method to load image then ProgressBar as parameter to that method may help you to hide ProgressBar:

https://stackoverflow.com/a/32666637/5045178

Upvotes: 1

SpyZip
SpyZip

Reputation: 5540

You can try this: https://github.com/vinaysshenoy/enhanced-volley there is Animation added to Volley.

also you can use

NetworkImageView ivImage = (NetworkImageView) rootView.findViewById(R.id.ivImage);
ivImage.setImageUrl(key, mImageLoader);
ivImage.setDefaultImageResId(R.drawable.loading_text);

where for me drawable loading_text was image saying "Loading image..."

Upvotes: 1

Itai Hanski
Itai Hanski

Reputation: 8680

You can create your own implementation of the ImageListener class and pass it when requesting the image.

Something along the lines of:

// code for displaying animation / progress wheel

sImageLoader.get(imageUrl, new ImageListener() {

    @Override
    public void onErrorResponse(VolleyError error) {
        // handle errors
    }

    @Override
    public void onResponse(ImageContainer response, boolean isImmediate) {
        if (response.getBitmap() != null) {
            // code to switch out placeholder animation 
            // progress wheel with received response
        }
    }
});

Upvotes: 3

Related Questions