I'm trying to use both fitCenter and placeholder but the image does not get resized.
This code works fine (image is scaled down, aspect ratio is correct):
Glide.with(this).load(url).fitCenter().into(mImage);
This code does not work (placeholder is correct, but loaded image appears squished, aspect ratio is wrong):
Glide.with(this).load(url).placeholder(R.drawable.placeholder).fitCenter().into(mImage);
Here is an example app demonstrating the problem with 2 imageviews side by side. Strangely in this app I could only reproduce the problem with centerCrop(), but something weird is going on with both.
The code is:
Glide.with(this).load("http://placehold.it/200x600.png").centerCrop().crossFade().into(img1);
Glide.with(this).load("http://placehold.it/200x600.png").centerCrop().placeholder(R.drawable.placeholder).crossFade().into(img2);
The images should have identical results since they both load the same URL. But what I get looks like the attached image. I also attached the sample project.
I have tracked this down to the use of TransitionDrawable between the placeholder image and the loaded image. TransitionDrawable does not handle having images with different dimensions, causing the issue. It is possible to avoid the problem by calling doNotAnimate() however obviously you lose the nice cross fade effect. Not sure what the best fix is.. write a replacement for TransitionDrawable that can work with drawables of different dimensions?
Hi, you are correct, this is a duplicate of #363.
You can also use fade in to fix it.
If you write that Drawable and share/contribute it, we will be eternally grateful! :)
OK, understood. Yes that seems more challenging than I first thought.
This definitely still an issue. Which issue should i be referencing/following for updates regarding this? I tried to follow your rabbit whole of progressively less relevant issues above but found not solution in any of them?
@xbroak #363 is still open, I duplicated everything against that, you only needed to follow one link. Click Subscribe in the right column on that issue.
My last comment there (and "added a commit" references around it) are the best workarounds so far, though it may need some additional coding to accommodate more use cases, but I think you found that, because someone upvoted both my answers an hour ago :wink:
There's no solution, only workarounds: .dontAnimate(), .animate(R.anim.fade_in), or that padded view adapter on SO.
The "only" thing missing for a proper fix is a general purpose TransitionDrawable (Android's version is not good enough as you see) that can cross-fade between any two Drawables of any size, without assuming anything about their types or aspect ratios' relationship. This magic Drawable also has to handle constant states properly, and animated Drawables through callbacks and delegate when necessary.
@TWiStErRob Great, thank you for the prompt response! No complaints here that a concrete fix is not in place, just wanted to be in the loop for when/if it is so i can remove the workarounds!
Most helpful comment
@xbroak #363 is still open, I duplicated everything against that, you only needed to follow one link. Click Subscribe in the right column on that issue.
My last comment there (and "added a commit" references around it) are the best workarounds so far, though it may need some additional coding to accommodate more use cases, but I think you found that, because someone upvoted both my answers an hour ago :wink:
There's no solution, only workarounds:
.dontAnimate(),.animate(R.anim.fade_in), or that padded view adapter on SO.The "only" thing missing for a proper fix is a general purpose
TransitionDrawable(Android's version is not good enough as you see) that can cross-fade between any two Drawables of any size, without assuming anything about their types or aspect ratios' relationship. This magic Drawable also has to handle constant states properly, and animated Drawables through callbacks and delegate when necessary.