当前位置:网站首页>流行框架: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);
边栏推荐
- vscode 常用插件汇总
- ViewModel 初体验
- Common content type correspondence table
- How to operate and invest games on behalf of others at sea
- MySQL version 8 installation Free Tutorial
- Migration from go vendor project to mod project
- 去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]
- R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据
- 吃透Chisel语言.06.Chisel基础(三)——寄存器和计数器
- [C question set] of VII
猜你喜欢
![Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]](/img/af/a1dcba6f45eb4ccc668cd04a662e9c.png)
Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]

sharding key type not supported

vscode 常用插件汇总

吃透Chisel语言.06.Chisel基础(三)——寄存器和计数器

Vscode common plug-ins summary

docker-compose公网部署redis哨兵模式
![去除重复字母[贪心+单调栈(用数组+len来维持单调序列)]](/img/af/a1dcba6f45eb4ccc668cd04a662e9c.png)
去除重复字母[贪心+单调栈(用数组+len来维持单调序列)]

Detailed index of MySQL

Applet live + e-commerce, if you want to be a new retail e-commerce, use it!

Ruiji takeout notes
随机推荐
How to package QT and share exe
markdown 语法之字体标红
Gorm read / write separation (rotation)
Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]
Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
92.(cesium篇)cesium楼栋分层
Fs4059c is a 5V input boost charging 12.6v1.2a. Inputting a small current to three lithium battery charging chips will not pull it dead. The temperature is 60 ° and 1000-1100ma is recommended
Golang uses JSON unmarshal number to interface{} number to become float64 type (turn)
Introducing testfixture into unittest framework
Code hoof collection of wonderful secret place
LiveData
瑞吉外卖笔记
海外游戏代投需要注意的
【信息检索】分类和聚类的实验
MATLAB中tiledlayout函数使用
R language ggplot2 visualization: gganimate package creates animated graph (GIF) and uses anim_ The save function saves the GIF visual animation
按照功能对Boost库进行分类
The game goes to sea and operates globally
【信息检索】链接分析
Unittest框架之断言