Glide does not resolve its method

女生的网名这么多〃 提交于 2019-12-17 15:38:16

问题


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?


回答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);



回答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);



回答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




回答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




回答5:


Glide version: 4.8.0

Glide.with(this)
        .load("https://media.giphy.com/media/98uBZTzlXMhkk/giphy.gif")
        .apply(new RequestOptions()
                .placeholder(R.drawable.placeholder)
                .error(R.drawable.error)
                .centerCrop()
                .fitCenter())
        .into(imageView);



回答6:


If you still want to use the newest library 'com.github.bumptech.glide:glide:4.0.0-RC1', The official Github page suggests the following:

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.

Otherwise use the following library version:

compile 'com.github.bumptech.glide:glide:3.7.0'



回答7:


compile this library:-

compile 'com.github.bumptech.glide:glide:3.7.0'


来源:https://stackoverflow.com/questions/44198856/glide-does-not-resolve-its-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!