当前位置:网站首页>流行框架: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);
边栏推荐
- The game goes to sea and operates globally
- China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder
- 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
- LiveData
- 如何游戏出海代运营、游戏出海代投
- R语言使用dplyr包的mutate函数对指定数据列进行标准化处理(使用mean函数和sd函数)并基于分组变量计算标准化后的目标变量的分组均值
- golang fmt. Printf() (turn)
- R language ggplot2 visualization: gganimate package creates animated graph (GIF) and uses anim_ The save function saves the GIF visual animation
- 92.(cesium篇)cesium楼栋分层
- Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]
猜你喜欢
How to package QT and share exe
392. Judgement subsequence
TestSuite and testrunner in unittest
Unity Shader学习(三)试着绘制一个圆
Xcode 异常图片导致ipa包增大问题
按照功能对Boost库进行分类
MySQL之详解索引
Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators
1200. Minimum absolute difference
基于51单片机的超声波测距仪
随机推荐
sql优化之explain
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
docker-compose公网部署redis哨兵模式
数据仓库面试问题准备
Gorm read / write separation (rotation)
92.(cesium篇)cesium楼栋分层
[antd step pit] antd form cooperates with input Form The height occupied by item is incorrect
Matters needing attention in overseas game Investment Agency
Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]
富文本编辑:wangEditor使用教程
MySQL之详解索引
Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test
IP 实验室月复盘 · 第 5 期
Understand chisel language thoroughly 10. Chisel project construction, operation and testing (II) -- Verilog code generation in chisel & chisel development process
LifeCycle
sharding key type not supported
Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]
File creation, writing, reading, deletion (transfer) in go language
R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据
Mongodb commonly used 28 query statements (forward)