Android 使用Glide加载图片

Glide是一个用来加载图片的工具,使用Glide加载图片有很多好处,比如大像素的图片Glide会自动进行压缩,不需要担心内存溢出的问题。

使用步骤

  • 加载Glide依赖:

最新版可以访问Glide的github主页:https://github.com/bumptech/glide

  • 使用Glide类调用静态with()方法获得一个RequestManager实例,这个方法有以下重载。
    1. public static RequestManager with(@NonNull Context context)
    2. public static RequestManager with(@NonNull Activity activity)
    3. public static RequestManager with(@NonNull View view)
  • 用RequestManager实例调用load()方法加载图片,并获得一个RequestBuilder的实例,这个方法有以下重载。
    1. public RequestBuilder<Drawable> load(@RawRes @DrawableRes @Nullable Integer resourceId) //用这个方法可以直接传入项目中图片的id了
    2. public RequestBuilder<Drawable> load(@Nullable Bitmap bitmap)
    3. public RequestBuilder<Drawable> load(@Nullable Uri uri)
    4. public RequestBuilder<Drawable> load(@Nullable URL url)
    5. public RequestBuilder<Drawable> load(@Nullable File file)
  • 用RequestBuilder的实例调用into()方法为布局中的组件设置图片

public ViewTarget<ImageView, TranscodeType> into(@NonNull ImageView view)

例子

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值