android glide流程解析,android-Glide无法解析其方法

android-Glide无法解析其方法

今天,我试图在我的android应用程序中使用fitCenter()图像加载程序,而使用此程序时,我遇到的方法无法解决问题。

Glide

.with(this)

.load(R.drawable.image_default_profile_picture)

.into(mUserImage);

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

Glide

.with(this)

.load(R.drawable.image_default_profile_picture)

.placeholder(R.mipmap.ic_launcher)

.fitCenter()

.into(mUserImage);

那么这句话无法解决方法fitCenter()、placeholder。我缺少什么?

7个解决方案

103 votes

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

Glide

.with(this)

.load(R.drawable.image_default_profile_picture)

.apply(new RequestOptions()

.placeholder(R.mipmap.ic_launcher)

.fitCenter())

.into(mUserImage);

Pehlaj answered 2020-01-22T13:48:24Z

45 votes

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

Glide.with(this)

.load(floorplanUrl)

.apply(new RequestOptions()

.placeholder(R.drawable.floorplan_unavailable))

.into(floorplanImageView);

James Jordan Taylor answered 2020-01-22T13:48:44Z

37 votes

如果您使用Glide包依赖性glide:glide:4.1.1,而不是使用以下代码

Glide

.with(your_context)

.load(image_url)

.centerCrop()

.placeholder(R.drawable.image_loading)

.error(R.drawable.image_error)

.into(imageView);

注意:与doc中一样   圆形图片:CircleImageView / CircularImageView / RoundedImageView是   已知与TransitionDrawable(.crossFade()   .thumbnail()或.placeholder())和动画GIF,请使用   BitmapTransformation(.circleCrop()在v4中可用)或   .dontAnimate()解决此问题。

最新更新版本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);

如果要使用glide:glide:4.1.1将glide:glide:4.1.1加载到GIF中,而不是在glide:glide:4.1.1之后使用glide:glide:4.1.1方法

Glide

.with(your_context)

.load(image_url)

.asGif()

.into(imageView);

如果您使用glide:glide:4.1.1或更高的(最新)依赖关系,

Glide

.with(your_context)

.asGif()

.load(image_url)

.into(imageView);

注意:如果使用的是glide:glide:4.1.1或更高版本,而不是不必要的.asGif()方法来加载GIF文件,它将自动加载GIF File

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

ND1010_ answered 2020-01-22T13:49:32Z

15 votes

要在v4.0以后的Glide版本中使用fitCenter()和其他比例类型更改,您需要在应用中包含特殊类。

import com.bumptech.glide.annotation.GlideModule;

import com.bumptech.glide.module.AppGlideModule;

@GlideModule

public class MyAppGlideModule extends AppGlideModule {

}

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

GlideApp.with(imageView)

.load("...")

.fitCenter()

.into(imageView);

文献资料

Airon Tark answered 2020-01-22T13:50:01Z

4 votes

滑行版本: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);

shellhub answered 2020-01-22T13:50:21Z

1 votes

如果您仍然想使用最新的库'com.github.bumptech.glide:glide:4.0.0-RC1',Github官方页面将建议以下内容:

圆形图片:CircleImageView / CircularImageView / RoundedImageView是   已知与TransitionDrawable(.crossFade()   .thumbnail()或.placeholder())和动画GIF,请使用   BitmapTransformation(.circleCrop()在v4中可用)或   .dontAnimate()解决此问题。

否则,请使用以下库版本:

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

Darush answered 2020-01-22T13:50:50Z

-2 votes

编译该库:

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

V.N.G answered 2020-01-22T13:51:10Z

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值