Skip to content

Instantly share code, notes, and snippets.

Created May 31, 2013 09:16
Show Gist options
  • Star 37 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save benvd/5683818 to your computer and use it in GitHub Desktop.
Save benvd/5683818 to your computer and use it in GitHub Desktop.
Extension of Volley's NetworkImageView that fades in images as they're loaded
import android.content.Context;
import android.util.AttributeSet;
public class FadeInNetworkImageView extends NetworkImageView {
private static final int FADE_IN_TIME_MS = 250;
public FadeInNetworkImageView(Context context) {
public FadeInNetworkImageView(Context context, AttributeSet attrs) {
super(context, attrs);
public FadeInNetworkImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
public void setImageBitmap(Bitmap bm) {
TransitionDrawable td = new TransitionDrawable(new Drawable[]{
new ColorDrawable(android.R.color.transparent),
new BitmapDrawable(getContext().getResources(), bm)
Copy link

Thank you bro.. this how I like sample code.. clear and working!

Copy link

Thanks a lot for the gist. It's succinct and works perfectly!

Copy link

cbeyls commented Apr 5, 2014

Thanks for the example code, but would it not be more efficient to use an AlphaAnimation on the ImageView instead? Like this:

Copy link

T-Spoon commented Jun 25, 2014

Just to note - this adds an extra layer of overdraw. You can use:


to remove this extra overdraw.

Copy link

thanks !

Copy link

Any way to pinchzoom the network image view???

Copy link

CRamsan commented May 16, 2015

Creating a new array, ColorDrawable, and BitmapDrawable is very inefficient I would suggest to declare them as private variables and reuse them instead.

Copy link

slott commented May 20, 2015

For starters this will eliminate one "new".

private static ColorDrawable cd = new ColorDrawable(android.R.color.transparent);

and then

    TransitionDrawable td = new TransitionDrawable(new Drawable[]{
            new BitmapDrawable(getContext().getResources(), bm)

Copy link

Teiby1 commented Jul 4, 2015

ColorDrawable can be replaced by getDrawable() if setDefaultImageResId() was called before.

Copy link

Very useful! Is possible to remove the effect once that an image has been viewed? In a list of images the effect is annoying when scroll down and scroll up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment