I have got this code to crossfade the background of an ImageView:
private void setWithCrossfade(Bitmap bitmap) {
//create drawable vector
Drawable backgrounds[] = new Drawable[2];
//getting first image
backgrounds[0] = mImageView.getDrawable();
backgrounds[1] = new BitmapDrawable(mImageView.getResources(), bitmap);
TransitionDrawable transitionDrawable = new TransitionDrawable(backgrounds);
transitionDrawable.setCrossFadeEnabled(true);
mImageView.setAdjustViewBounds(false);
mImageView.setImageDrawable(transitionDrawable);
//it is needed to reset scale type
mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//start crossfading
transitionDrawable.startTransition(250);
}
The ImageView scaleType is set to centerCrop in the XML layout. However, when the crossfade finishes, the new bitmap is set to fitXY. In other thread they say it can be solved by resetting the scaleType, but it is not working either. Resizing the bitmap is not a proper solution in terms of memory. Is there any workaround to implement this? Thank you very much.
P.S.: Please, do not suggest crossfading 2 ImageViews, or using a ViewSwitcher thanks.