Glide does not resolve its method

Today I'm trying to use Glide image loader in my android application while using this I had facing method not resolving problem.

Glide
     .with(this)
     .load(R.drawable.image_default_profile_picture)
     .into(mUserImage);

This code working pretty fine. But when I'm trying this

Glide
     .with(this)
     .load(R.drawable.image_default_profile_picture)
     .placeholder(R.mipmap.ic_launcher)
     .fitCenter()
     .into(mUserImage);

Then this saying cannot resolve method fitCenter(), placeholder. What I am missing?


Solution 1:

Seems like updated library has any issue. Add .apply(new RequestOptions() to continue with latest version.

CODE

Glide
 .with(this)
 .load(R.drawable.image_default_profile_picture)
 .apply(new RequestOptions()
 .placeholder(R.mipmap.ic_launcher)
 .fitCenter())
 .into(mUserImage);

Solution 2:

You can still use .placeholder() with the latest version of Glide, you just have to add it as an applied RequestOption in the method chain, i.e.

Glide.with(this)
     .load(floorplanUrl)
     .apply(new RequestOptions()
           .placeholder(R.drawable.floorplan_unavailable))
     .into(floorplanImageView);

Solution 3:

If you use Glide package dependences compile 'com.github.bumptech.glide:glide:3.7.0' than use below code

Glide
    .with(your_context)
    .load(image_url)
    .centerCrop()
    .placeholder(R.drawable.image_loading)
    .error(R.drawable.image_error)
    .into(imageView);

Note: As in doc Round Pictures: CircleImageView/CircularImageView/RoundedImageView are known to have issues with TransitionDrawable (.crossFade() with .thumbnail() or .placeholder()) and animated GIFs, use a BitmapTransformation (.circleCrop() will be available in v4) or .dontAnimate() to fix the issue.

Latest update version compile 'com.github.bumptech.glide:glide:4.1.1' or above than use below code

Glide.with(your_context)
     .load(url)
     .apply(new RequestOptions()
                .placeholder(R.mipmap.ic_loading_image)
                .centerCrop()
                .dontAnimate()
                .dontTransform())
                .into(imageView);

If you want to load GIF File in to Glide with using compile 'com.github.bumptech.glide:glide:3.7.0' than use .asGif() method after .load()

Glide
    .with(your_context)
    .load(image_url)
    .asGif()
    .into(imageView);

If you use compile 'com.github.bumptech.glide:glide:4.1.1' or higher(latest) dependences than,

Glide
    .with(your_context)
    .asGif()
    .load(image_url)
    .into(imageView);

Note: If you are useing glide:glide:4.1.1 or higher version than not necessary to use .asGif() method to load GIF file it will load GIF File automatically

See Latest version of glide, Bug fixes, Features

Solution 4:

For using fitCenter() and other scale type changes with the Glide version starting from v4.0, you need include special class in your app.

import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

@GlideModule
public class MyAppGlideModule extends AppGlideModule {
}

After that rebuild the project, and you can start using Glide on that manner

GlideApp.with(imageView)
    .load("...")
    .fitCenter()
    .into(imageView);

Documentation