New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image size changed after being reloaded #1591
Comments
I added some log in |
Similar issue: |
I found a workaround: Glide.with(getContext())
.load(urls[i])
.listener(new RequestListener<Uri, GlideDrawable>() {
@Override
public boolean onException(Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, Uri model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
GlideDrawableImageViewTarget glideTarget = (GlideDrawableImageViewTarget) target;
ImageView iv = glideTarget.getView();
int width = iv.getMeasuredWidth();
int targetHeight = width * resource.getIntrinsicHeight() / resource.getIntrinsicWidth();
if(iv.getLayoutParams().height != targetHeight) {
iv.getLayoutParams().height = targetHeight;
iv.requestLayout();
}
return false;
}
})
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(viewHolder.imageView); |
The list items are being reused, and when you scroll down you bind a larger image which makes the ImageView layout taller (wrap_content). When you scroll back up Glide sees that taller size and tries to load an image that has that size. |
@TWiStErRob, Thanks for your reply. I tried to call |
I tried this but in the last line it tell me Cannot resolve method 'into(void)'
|
@Ennosukeblade I assume you have to call |
Adding
|
@jkailin that only works if you have a fixed width layout, and it'll also shrink taller than wide (portrait shape) images as a side effect. It also should not work on the first bind, interesting if it does for you. |
@TWiStErRob Ah that's right. Portrait images have issues. When I use |
@jkailin Based on the many upvotes to my original comment, yes :)
I'm not sure if it still exists in a fairly similar for in v4. |
centering image on the left, as you would with TextView |
Still happening, in my case I'm using different dimensionRatio (from ConstraintLayout) go show image, files and videos, and to fix the problem the solution was:
|
|
This is because when the view is created it has a height of 0, and when Glide loads the image suddenly the height of an item changes, so it pushes other items down/up (according to orientation scroll) Any idea how to fix this? |
@james04gr if you have a predefined height for the items, you can use that value for the bottom param. |
If you have predefined size (e.g. 123dp), just set |
3.7.0:
failed on com.android.support:recyclerview-v7:25.0.1:
failed on all devices I have, such as Nexus 5 6.0.1
expected result
unexpected result
**:
use Glide to load gif into items of recyclerview, then scroll the recyclerview up and down, the image size is changed after scrolling out of screen then into screen:
Glide load line /
GlideModule
(if any) / list Adapter code (if any):Layout XML:
Stack trace / LogCat:
The text was updated successfully, but these errors were encountered: