1

In my android application, I am using universal image loader to show images from url. During loading of image I want a gif image to be shown. But the gif image added is not showing any animation. Here is my code to display image.

private static final DisplayImageOptions.Builder DEFAULT_DISPLAY_IMAGE_OPTIONS_BUIDLER = new DisplayImageOptions.Builder()
        .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
        .displayer(new FadeInBitmapDisplayer(300, true, false, false))
        .showImageForEmptyUri(R.drawable.default_image)
        .showImageOnLoading(R.drawable.loadingx)
        .showImageOnFail(sampleapp.sample.com.sampleapp.R.drawable.default_image).cacheOnDisk(true)
        .cacheInMemory(true).bitmapConfig(Config.ARGB_8888);

what changes should I make to show an animated gif image during loading time image

Nikhil
  • 1,212
  • 13
  • 30
user1810
  • 121
  • 1
  • 2
  • 10

3 Answers3

0

Try to use glide for gif image loading...

Glide  
    .with( context )
    .load( gifUrl )
    .asGif()
    .error( R.drawable.full_cake )
    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
    .into( imageViewGif );

To understand follow the link - here

If you want to use ProgressBar then create a method like below -

public void loadImage(Context context, String url, ImageView img, final ProgressBar eProgressBar) {

        eProgressBar.setVisibility(View.VISIBLE);
        Glide.with(context)
                .load(url)
                .listener(new RequestListener<String, GlideDrawable>() {
                    @Override
                    public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                        eProgressBar.setVisibility(View.GONE);
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                        eProgressBar.setVisibility(View.GONE);
                        return false;
                    }
                })
                .crossFade()
                .error(R.drawable.placeholder_image)
                .into(img);
    }

Use this method and pass your parameter value through it... :)

Shohan Ahmed Sijan
  • 4,391
  • 1
  • 33
  • 39
Farya
  • 277
  • 3
  • 14
0

Universal Image Loader doesnot Support Gif see this Try using other libraries like Glide which supports gif

Glide.with(context)
    .load(imageUrl)
    .asGif()
    .placeholder(R.drawable.yourgif)
    .crossFade()
    .into(imageView);
Manohar
  • 22,116
  • 9
  • 108
  • 144
  • Does Universal Image Loader support default progressbar or spinner – user1810 May 16 '17 at 06:33
  • whats the relation between progressbar and image loader ,i cant understand what you are asking – Manohar May 16 '17 at 06:36
  • You said that universal image loader doesn't support gif. If so then I just need to show something moving during loading of image. There is default progress bar in android. This [link](http://stackoverflow.com/questions/13653816/show-indeterminate-progressbar-while-loading-image-with-universal-image-loader) show how to show progress bar during loading of image. I tried it,But it also causes some error. – user1810 May 16 '17 at 06:44
  • you can use an image of loading as place holder , Placeholder image will be shown until the original image is loaded. – Manohar May 16 '17 at 06:48
  • I used a gif image as place holder.But It does'nt show any animation. – user1810 May 16 '17 at 09:15
0

I got answer by using glide library. But glide is slower than universal image loader.

Glide.with(getActivity().getApplication())
                .load(item.imageUrl)
                .thumbnail(Glide.with(getActivity().getApplication()).load(R.drawable.loadingx))
                .fitCenter()
                .crossFade()
                .into(holder.image);
user1810
  • 121
  • 1
  • 2
  • 10