Universal image downloader using 2 displays

How can I add FadeInBitmapDisplayer and RoundedBitmapDisplayer to my image?

This is my DisplayImageOptions

options = new DisplayImageOptions.Builder() .showStubImage(R.drawable.appwidget .cacheInMemory().displayer(new FadeInBitmapDisplayer(1500)) .build(); 

And is it possible to somehow use the FadeIn effect once? And if it is loaded, and I scroll down my list and scroll back again, is it not FadeIn a second time?

Thanks in advance!

+4
source share
3 answers

How can I add FadeInBitmapDisplayer and RoundedBitmapDisplayer to my image?

There is no way in the current version. You can create your own display (extend BitmapDisplayer) and copy the code from FadeInBitmapDisplayer and RoundedBitmapDisplayer to your class.

And is it possible to somehow use the FadeIn effect once?

Almost everything is possible :) But it will not be very convenient.

You can save the displayed URLs of images on some map ( Map<String, Boolean> = [Image URL ↔ isDisplayed]) and check this map before calling imageLoader.displayImage(...) . If the image for the current URL is in Map (i.e. the image was displayed), use only the RoundedBitmapDisplayer options. If the image for the current URL is not in Map, then use the options with FadeInBitmapDisplayer + RoundedBitmapDisplayer.

+11
source

How to add FadeInBitmapDisplayer and RoundedBitmapDisplayer to my image?

There was also a problem. I used NOSTRA's great suggestion, and here is my custom class:

 public class FadeInRoundedBitmapDisplayer extends RoundedBitmapDisplayer { int durationMillis; String noRoundedCornersTag; public FadeInRoundedBitmapDisplayer(int durationMillis, int roundPixels, String noRoundedCornersTag) { super(roundPixels); this.durationMillis = durationMillis; this.noRoundedCornersTag = noRoundedCornersTag; } @Override public Bitmap display(Bitmap bitmap, ImageView imageView, LoadedFrom loadedFrom) { imageView.setImageBitmap((imageView.getTag() != null && imageView .getTag().equals(noRoundedCornersTag)) ? bitmap : super .display(bitmap, imageView, loadedFrom)); animate(imageView, durationMillis); return bitmap; } public static void animate(ImageView imageView, int durationMillis) { AlphaAnimation fadeImage = new AlphaAnimation(0, 1); fadeImage.setDuration(durationMillis); fadeImage.setInterpolator(new DecelerateInterpolator()); imageView.startAnimation(fadeImage); } } 

You can pass String noRoundedCornersTag to the constructor. This allows you to specify a single imageView tag in your XML layout to skip the corner radius procedure (useful for background images, etc.), for example:

 <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:tag="@string/no_rounded_corners_tag" /> 

The constructor call will look like this:

 new FadeInRoundedBitmapDisplayer(Constants.IMAGE_FADING_TIME, getResources().getDimension(R.dimen.image_corner_radius), getResources().getString(R.string.no_rounded_corners_tag)) 
+5
source

I had to update the @saschoar solution because it did not work with the current version of Universal Image Loader (1.9.4). The solution is pretty similar. Take a look:

 public class FadeInRoundedBitmapDisplayer extends RoundedBitmapDisplayer { int durationMillis; public FadeInRoundedBitmapDisplayer(int durationMillis, int roundPixels) { super(roundPixels); this.durationMillis = durationMillis; } @Override public void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom) { super.display(bitmap, imageAware, loadedFrom); animate(imageAware.getWrappedView(), durationMillis); } public static void animate(View imageView, int durationMillis) { AlphaAnimation fadeImage = new AlphaAnimation(0, 1); fadeImage.setDuration(durationMillis); fadeImage.setInterpolator(new DecelerateInterpolator()); imageView.startAnimation(fadeImage); } } 

You can use this solution to define DisplayImageOptions this way:

  DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder() .displayer(new FadeInRoundedBitmapDisplayer(3000, 1000)) .build(); ImageLoader imageLoader = ImageLoader.getInstance(); imageLoader.displayImage(imageUrl, imageView, displayImageOptions); 
+3
source

All Articles