当前位置:网站首页>流行框架: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
- QT how to detect whether the mouse is on a control
- Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT
- R语言使用lattice包中的bwplot函数可视化箱图(box plot)、par.settings参数自定义主题模式
- 2022 practice questions and mock exams for the main principals of hazardous chemical business units
- Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
- Programmer anxiety
- Gorm read / write separation (rotation)
- How to package QT and share exe
- 吃透Chisel语言.03.写给Verilog转Chisel的开发者(没有Verilog基础也可以看看)
猜你喜欢

Hardware Basics - diode Basics

MySQL之详解索引

Use of tiledlayout function in MATLAB

Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
![去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]](/img/af/a1dcba6f45eb4ccc668cd04a662e9c.png)
去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]

Excel快速合并多行数据

Excel quickly merges multiple rows of data

基于51单片机的超声波测距仪

Unity shader learning (3) try to draw a circle

1200. Minimum absolute difference
随机推荐
Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT
基于51单片机的超声波测距仪
Blob, text geometry or JSON column'xxx'can't have a default value query question
Matters needing attention in overseas game Investment Agency
docker-compose公网部署redis哨兵模式
Understand chisel language thoroughly 10. Chisel project construction, operation and testing (II) -- Verilog code generation in chisel & chisel development process
IDEA快捷键大全
Code hoof collection of wonderful secret place
Understand chisel language thoroughly 03. Write to the developer of Verilog to chisel (you can also see it without Verilog Foundation)
Unity shader learning (3) try to draw a circle
The font of markdown grammar is marked in red
Product identification of intelligent retail cabinet based on paddlex
PHP log debugging
Mongodb commonly used 28 query statements (forward)
TestSuite and testrunner in unittest
Test evaluation of software testing
做事的真正意义和目的,真正想得到什么
R language uses the DOTPLOT function of epidisplay package to visualize the frequency of data points in different intervals in the form of point graph, and uses the by parameter to specify the groupin
Understand chisel language thoroughly 06. Chisel Foundation (III) -- registers and counters
Introducing testfixture into unittest framework