Glide图片加载缓存框架的使用

本文介绍了Glide图片加载库的使用方法,包括如何在Android应用中集成Glide,加载网络图片,设置缓存签名,以及如何处理图片加载成功和失败的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

GitHub网址:
GitHub - bumptech/glide: An image loading and caching library for Android focused on smooth scrolling https://github.com/bumptech/glide

app的gradle添加依赖:

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

加载网络图片:

Glide.with(this)
.load("图片的Url")
.signature(new StringSignature("你的标记字符串"))//设置签名
.error(getResources().getDrawable(R.mipmap.img))//加载失败后的默认图片
.into(imageView);

signature(new StringSignature("你的标记字符串"))这是在设置签名,Glide自带了缓存机制,当Url对应的图片改变了,但Url没有改变,图片是不会更新的,所以设置签名后,当签名值改变了图片就会更新

加载图片成功和失败后的结果处理函数:

Glide.with(this).load("图片url")
                    .error(getResources().getDrawable(R.mipmap.img))//加载失败后的默认图片
                    .into(new GlideDrawableImageViewTarget(imageView) {
                        @Override
                        public void onLoadFailed(Exception e, Drawable errorDrawable) {
                            super.onLoadFailed(e, errorDrawable);
                            //图片加载失败后,你想以此为基础进行的一些处理操作可以写在这里
                        }

                        @Override
                        public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) {
                            super.onResourceReady(resource, animation);
                            //图片加载成功后,你想以此为基础进行的一些处理操作可以写在这里
                        }
                    });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值