Last Updated: February 25, 2016
·
741
· alouanemed

Android : how to animate transition between placeholder and image

Dev tip: how to animate transition between placeholder and image.

//Create a bitmap drawable from the bitmap to be shown
Drawable bitmapDrawable = new BitmapDrawable(context,bitmap);

Drawable[] layers = new Drawable[] {
imageView.getDrawable(), //Current placeholder
bitmapDrawable //Image to show
};

TransitionDrawable transitionDrawable = new TransitionDrawable(layers);

imageView.setImageDrawable(transitionDrawable);

int durationMillis = 1000;
transitionDrawable.startTransition(durationMillis);

source