Glide Version:
3.7.0
Integration libraries:
Device/Android Version:
all device
Issue details / Repro steps / Use case background:
i want display a image into ImageView with wrap_parent params, but glide alwlays display it as match_parent , i have a ImageView in my container i want use it to display a little pic, for example a little flower,but glide will display it full the screen,please tell me what's wrong with the code
Glide load line / GlideModule (if any) / list Adapter code (if any):
Glide.with(context).load(url).into(img);
Layout XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red"
android:gravity="top"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
You're telling Glide to load an image with screen size dimensions (implied from wrap_content) and .fitCenter() transformation (implied from default scaleType on ImageView).
You need to add android:scaleType="center" to prevent the transformation and display the small image correctly; or add .dontTransform() in code; or add .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) in code.
copy that
don't use ORIGINAL size, it will eat more memory, glide should get width and height of ImageView and load optimal image size, so you have to replace WRAP_CONTENT with some fixed size, now in Android it's better to do with ConstraintLayout, you can even set aspect for ImageView
@anonym24 but if we use fixed size there will be blank spaces in imageview. So it isn't a solution.
Most helpful comment
You're telling Glide to load an image with screen size dimensions (implied from wrap_content) and
.fitCenter()transformation (implied from default scaleType on ImageView).You need to add
android:scaleType="center"to prevent the transformation and display the small image correctly; or add.dontTransform()in code; or add.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)in code.