I have an ImageView with match_parent width and wrap_content height like this:
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
How to load an image (http://lorempixel.com/400/600/) using Glide that fit with ImageView and keeps the aspect ratio of the image?
Have you tried:
ImageView imageView = (ImageView)findViewById(R.id.image);
Glide.with(this).load("http://lorempixel.com/400/600/").into(imageView);
The default ImageView.scaleType is FIT_CENTER, which Glide recognizes and uses .fitCenter() implicitly. See source code of GenericRequestBuilder.into(ImageView) method.
I've tried your solution but the image doesn't fit with the width of the layout. The layout_width of my ImageView is match_parent, so the image's width should follow the layout width which is match_parent. I've tried using fitXY, but it doesn't keep the aspect ratio of the image. Look at the result below:
Load image from http://lorempixel.com/400/400/ (this is what I want in 400x600 and other ratios, the width is match_parent):

Load from http://lorempixel.com/400/600/ using fitXY:

Load from http://lorempixel.com/400/600/ using default configuration:

and why GenericRequestBuilder.into(ImageView) doesn't handle all scaleType?
thank you :)
wrap_content defaults to screen height so if your ratio would overshoot that you get a fitted image. What you probably want is .override(screenWidth, Target.SIZE_ORIGINAL).fitCenter(), to display images taller than the screen, but consider that it's probably bad UX (IMO).
It does support all the scale types, the default applies to the non-mentioned ones.
that's true to use Target.SIZE_ORIGINAL
Most helpful comment
wrap_contentdefaults to screen height so if your ratio would overshoot that you get a fitted image. What you probably want is.override(screenWidth, Target.SIZE_ORIGINAL).fitCenter(), to display images taller than the screen, but consider that it's probably bad UX (IMO).