Glide无法解决其方法

use*_*954 52 android android-glide

今天我正在尝试Glide在我的Android应用程序中使用图像加载器,同时使用这个我面对的方法没有解决问题.

Glide
     .with(this)
     .load(R.drawable.image_default_profile_picture)
     .into(mUserImage);
Run Code Online (Sandbox Code Playgroud)

这段代码工作得很好.但是当我尝试这个时

Glide
     .with(this)
     .load(R.drawable.image_default_profile_picture)
     .placeholder(R.mipmap.ic_launcher)
     .fitCenter()
     .into(mUserImage);
Run Code Online (Sandbox Code Playgroud)

然后这句话无法解决方法fitCenter(),placeholder.我错过了什么?

Peh*_*laj 105

好像更新的库有任何问题.添加.apply(new RequestOptions()以继续使用最新版本.

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


Jam*_*lor 45

您仍然可以使用.placeholder()最新版本的Glide,您只需将其添加为RequestOption方法链中的应用,即

Glide.with(this)
     .load(floorplanUrl)
     .apply(new RequestOptions()
           .placeholder(R.drawable.floorplan_unavailable))
     .into(floorplanImageView);
Run Code Online (Sandbox Code Playgroud)


ND1*_*10_ 37

如果你使用Glide包依赖而 compile 'com.github.bumptech.glide:glide:3.7.0'不是使用下面的代码

Glide
    .with(your_context)
    .load(image_url)
    .centerCrop()
    .placeholder(R.drawable.image_loading)
    .error(R.drawable.image_error)
    .into(imageView);
Run Code Online (Sandbox Code Playgroud)

注意:如在文档 圆形图片中:已知CircleImageView/CircularImageView/RoundedImageView与TransitionDrawable(.crossFade()与.thumbnail()或.placeholder())和动画GIF有关,使用BitmapTransformation(.circleCrop()将是在v4)或.dontAnimate()中可用来解决问题.

最新更新版本compile 'com.github.bumptech.glide:glide:4.1.1'或以上使用以下代码

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

如果要使用之后加载GIF FileGlide使用compile 'com.github.bumptech.glide:glide:3.7.0'比使用.asGif()方法.load()

Glide
    .with(your_context)
    .load(image_url)
    .asGif()
    .into(imageView);
Run Code Online (Sandbox Code Playgroud)

如果你使用compile 'com.github.bumptech.glide:glide:4.1.1'或更高(最新)依赖,

Glide
    .with(your_context)
    .asGif()
    .load(image_url)
    .into(imageView);
Run Code Online (Sandbox Code Playgroud)

注意:如果您使用的是glide:glide:4.1.1更高版本而不是使用.asGif()方法加载GIF文件,则会GIF File自动加载

查看最新版本的滑翔,错误修复,功能


Air*_*ark 16

对于使用fitCenter()从v4.0开始的Glide版本进行的其他比例类型更改,您需要在应用程序中包含特殊类.

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

@GlideModule
public class MyAppGlideModule extends AppGlideModule {
}
Run Code Online (Sandbox Code Playgroud)

在重建项目之后,您可以开始以这种方式使用Glide

GlideApp.with(imageView)
    .load("...")
    .fitCenter()
    .into(imageView);
Run Code Online (Sandbox Code Playgroud)

文档