How to fit Image into ImageView using Glide

N J picture N J · Dec 1, 2015 · Viewed 71.8k times · Source

My concern is how to fit image using android:scaleType="fitXY" into image using Glide.

My ImageView is

<ImageView
    android:id="@+id/img_pager"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:scaleType="fitXY" />

Loads image using Glide like this

Glide.with(context).load(url).placeholder(R.drawable.default_image).into(img);

but image is not getting fit into ImageView it show space on image either side as shown in screen I need it fitXY

enter image description here

Answer

OriolJ picture OriolJ · Aug 17, 2017

On Glide v4 you have to create a RequestOptions object, like this:

RequestOptions options = new RequestOptions();
options.centerCrop();

Glide.with(fragment)
    .load(url)
    .apply(options)
    .into(imageView);

More info