Glide Version: 4.0.0-SNAPSHOT
Integration libraries: okhttp3-integration:4.0.0-RC0@aar
Device/Android Version: Galaxy S6 Edge, Android 7
Issue details / Repro steps / Use case background:
I want to load an image into an ImageView with a defined height but a wrap_content height and can't get this working. Image is always smaller than the ImageViews width...
I've seen this https://github.com/bumptech/glide/issues/1410 but it does not help me. The suggested solutions don't work....
My solution is following 2 adjustments:
.override(dp64) to my requestandroid:scaleType="fitCenter" for the ImageViewBut this means hardcoded width in code which could be automatically derived from the view so this is not perfect. And that the height may be cropped. Any better solution?
Glide load line / GlideModule (if any) / list Adapter code (if any):
GlideApp.with(iv)
.load(url)
.into(iv);
Layout XML:
<ImageView
android:id="@+id/ivImage"
android:scaleType="fitCenter"
android:layout_width="64dp"
android:layout_height="wrap_content" />
Finally I found the solution with a answer from TWiStErRob here:
https://stackoverflow.com/a/25069883/1439522
The simple solution is to only setup the ImageView like following:
<ImageView
android:id="@+id/ivImage"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:layout_width="64dp"
android:layout_height="wrap_content" />
android:adjustViewBounds is the key here...
My Glide version : 4.9.0
<!-- my ImageView: -->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
public static void showRoundedCornerImage(ImageView imageView,
String url, int maxHeight,int maxWidth,int corner) {
Context context = imageView.getContext();
corner = OsUtils.dp2px(context, corner);
maxHeight = OsUtils.dp2px(context, maxHeight);
maxWidth = OsUtils.dp2px(context, maxWidth);
Glide.with(context)
.load(url)
.fitCenter()
.transform(new RoundedCorners(corner))
.override(maxWidth,maxHeight)
.into(imageView);
}
Most helpful comment
Finally I found the solution with a answer from TWiStErRob here:
https://stackoverflow.com/a/25069883/1439522
The simple solution is to only setup the
ImageViewlike following:android:adjustViewBoundsis the key here...