当前位置:网站首页>流行框架: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);
边栏推荐
- JVM memory layout detailed, illustrated, well written!
- Gorm read / write separation (rotation)
- 1200. Minimum absolute difference
- 如何游戏出海代运营、游戏出海代投
- Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators
- vscode 常用插件汇总
- Introducing testfixture into unittest framework
- Understand chisel language thoroughly 08. Chisel Foundation (V) -- wire, REG and IO, and how to understand chisel generation hardware
- How to operate and invest games on behalf of others at sea
- The game goes to sea and operates globally
猜你喜欢

MySQL之详解索引

Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators

Understand chisel language thoroughly 06. Chisel Foundation (III) -- registers and counters

吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行

为什么图片传输要使用base64编码

Unittest框架中引入TestFixture

Data warehouse interview question preparation
![[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp](/img/eb/11e5da1c5e897c5f6a18d49125925f.png)
[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp

Oppo find N2 product form first exposure: supplement all short boards

Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million
随机推荐
Test process arrangement (2)
BLOB,TEXT GEOMETRY or JSON column 'xxx' can't have a default value query 问题
R language uses dplyr package group_ The by function and the summarize function calculate the mean and standard deviation of the target variables based on the grouped variables
DDD application and practice of domestic hotel transactions -- Code
吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
Programmer anxiety
392. Judgement subsequence
软件测试之测试评估
R语言使用lattice包中的bwplot函数可视化箱图(box plot)、par.settings参数自定义主题模式
Introducing testfixture into unittest framework
【信息检索】分类和聚类的实验
Understand chisel language thoroughly 10. Chisel project construction, operation and testing (II) -- Verilog code generation in chisel & chisel development process
sharding key type not supported
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
Innovation and development of independent industrial software
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
Apple 5g chip research and development failure: continue to rely on Qualcomm, but also worry about being prosecuted?
Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder
R language ggplot2 visualization: gganimate package creates animated graph (GIF) and uses anim_ The save function saves the GIF visual animation