Skip to content

Instantly share code, notes, and snippets.

@folivares
Forked from benvd/FadeInNetworkImageView.java
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save folivares/6e1074ed25558a8a683a to your computer and use it in GitHub Desktop.
Save folivares/6e1074ed25558a8a683a to your computer and use it in GitHub Desktop.
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.*;
import android.util.AttributeSet;
import com.android.volley.toolbox.NetworkImageView;
public class FadeInNetworkImageView extends NetworkImageView {
private static final int FADE_TRANSITION_MILLISECONDS = 500;
private static ColorDrawable cd = new ColorDrawable(android.R.color.transparent);
public FadingNetworkImageView(Context context) {
super(context);
}
public FadingNetworkImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FadingNetworkImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void setImageBitmap(Bitmap bitmap) {
TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[]{
cd,
new BitmapDrawable(getContext().getResources(),bitmap)
});
transitionDrawable.setCrossFadeEnabled(true);
setImageDrawable(transitionDrawable);
transitionDrawable.startTransition(FADE_TRANSITION_MILLISECONDS);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment