Set TransitionDrawable with ImageView ScaleType

I have this code to cross out the ImageView background:

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);
}

ImageView is scaleTypeset to centerCropin XML layout. However, when the crossfade ends, the new bitmap is set to fitXY. In another thread, they say that this can be solved by dropping scaleType, but it does not work. Resizing a bitmap image is not a good solution in terms of memory. Is there any way around this? Thank you very much.

PS: Please do not offer crossfading 2 ImageViews or thanks to ViewSwitcher.

+4
source share
1 answer

. , TransitionDrawable . , . . PicassoDrawable Picasso , .

PicassoDrawable.setPlaceholder(imageView, placeholderDrawable);
PicassoDrawable.setBitmap(imageView, context, bitmap);

. , Picasso. .

+2

All Articles