当前位置:网站首页>流行框架:Glide的使用
流行框架:Glide的使用
2022-07-04 12:51:00 【Y.IU.】
引入依赖
implementation 'com.github.bumptech.glide:glide:4.11.0'
Glide占位符
- placeholder 正在请求图片时展示的图片
- error 请求失败时展示的图片 (如果没有设置,就展示placeholder占位图)
- fallback 请求的url为null时展示的图片(如果没有设置,就展示placeholder占位图)
配置占位符的使用:
RequestOptions ro = new RequestOptions()
.placeholder(图片路径)
.error(图片路径)
.fallback(图片路径)
具体使用:
Glide.with(fragment/activity/view)
.load(url)
.apply(ro)
.with(imageView);
过渡与转换
过渡:transition
从占位符到新加载的图片的动画
避免占位符在动画后还能显示
DrawableCrossFadeFactory fadeFactory = new DrawableCrossFadeFactory .Builder().setCrossFadeEnabled(true).build();
实现代码
Glide.with(this)
.load("https://img1.baidu.com/it/u=722430420,1974228945&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500")
.apply(options)
.transition(DrawableTransitionOptions.withCrossFade(fadeFactory).crossFade(1000))
.into(imageView);
转换:transform
- CircleCrop:圆角
- RoundedCorners:四个角度统一指定
- GranulaRoundedCorners:四个角度单独指定
- Rotate:旋转
实现代码
.transform(new CircleCrop())
Generated API
引入依赖,这个依赖相当于代码生成器
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
在Application中的模块中引入AppGlideModule的实现。(将AppGlideModule配置的项目当中)
/** * 配置类 */ @GlideModule public class MyAppModule extends AppGlideModule { }
点击Bulid -> Make Module … 进行编译
最后就可以通过GlideApp实现Glide一样的效果,而且只需要在GlideApp上通过 . 的方式实现就行
GlideApp.with(this)
.load("")
.placeholder(R.drawable.icon1)
.error(R.drawable.icon2)
.fallback(R.drawable.icon3)
.into(imageView);
GlideExtension和GlideOption
如果选项集合需要频繁使用,可以通过配置类并且写上GlideExtension和GlideOption的注解。
@GlideExtension
public class MyAppExtension {
private MyAppExtension() {
// 必须是私有的
}
@GlideOption
public static BaseRequestOptions<?> defaultImg(BaseRequestOptions<?> options) {
return options.placeholder(R.drawable.icon1)
.error(R.drawable.icon2)
.fallback(R.drawable.icon3);
}
}
具体使用
GlideApp.with(this).load("").defaultImg().into(imageView);
边栏推荐
- File creation, writing, reading, deletion (transfer) in go language
- 1200. Minimum absolute difference
- GCC [6] - 4 stages of compilation
- Assertion of unittest framework
- gorm 之数据插入(转)
- markdown 语法之字体标红
- R language dplyr package summary_ If function calculates the mean and median of all numerical data columns in dataframe data, and summarizes all numerical variables based on conditions
- Innovation and development of independent industrial software
- Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder
- Mongodb commonly used 28 query statements (forward)
猜你喜欢
递增的三元子序列[贪心训练]
Incremental ternary subsequence [greedy training]
[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp
Understand chisel language thoroughly 10. Chisel project construction, operation and testing (II) -- Verilog code generation in chisel & chisel development process
Mask wearing detection based on yolov1
C# wpf 实现截屏框实时截屏功能
富文本编辑:wangEditor使用教程
【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结
基于YOLOv1的口罩佩戴检测
迅为IMX6Q开发板QT系统移植tinyplay
随机推荐
IDEA快捷键大全
吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest
安装Mysql
Apple 5g chip research and development failure: continue to rely on Qualcomm, but also worry about being prosecuted?
Huahao Zhongtian rushes to the scientific and Technological Innovation Board: the annual loss is 280million, and it is proposed to raise 1.5 billion. Beida pharmaceutical is a shareholder
sql优化之explain
递增的三元子序列[贪心训练]
The game goes to sea and operates globally
MySQL之详解索引
qt 怎么检测鼠标在不在某个控件上
Gorm data insertion (transfer)
Rich text editing: wangeditor tutorial
vscode 常用插件汇总
LiveData
【信息检索】链接分析
Use the default route as the route to the Internet
sharding key type not supported
基于PaddleX的智能零售柜商品识别
92.(cesium篇)cesium楼栋分层
GCC【6】- 编译的4个阶段