4.Glide使用之图片占位及过渡动画

编程入门 行业动态 更新时间:2024-10-04 15:39:16

4.Glide使用之图片占位及过渡<a href=https://www.elefans.com/category/jswz/34/1769013.html style=动画"/>

4.Glide使用之图片占位及过渡动画

重点内容
为了更好的用户体验,我们在开发的时候一般会给图片放置一张加载过程的图片。一般加载图片大部分都是网络图片,加载速度取决于用户所在的环境,最好的方式是加载时显示一个占位图片,成功之后展示正确的图片。

Glide使用图片占位placeholder()(placeholder()的参数是drawable/mipmap资源的引用)

Glide.with(context).load(UsageExampleListViewAdapter.eatFoodyImages[0]).placeholder(R.mipmap.ic_launcher) // can also be a drawable.into(imageViewPlaceholder);

当然,你不能设置一个网络图片的URL作为占位符,因为那也需要加载,应用的资源和drawable要保证是可用可访问的。当然,不能加载或加载失败也可以设置占位图

Glide使用错误图片占位error() (注:error()参数为drawable/mipmap资源)

Glide.with(context).load(".png").placeholder(R.mipmap.ic_launcher) // can also be a drawable.error(R.mipmap.future_studio_launcher) // will be displayed if the image cannot be loaded.into(imageViewError);

Glide加载图片使用渐入动画crossFade() 默认使用渐变动画

Glide.with(context).load(UsageExampleListViewAdapter.eatFoodyImages[0]).placeholder(R.mipmap.ic_launcher) // can also be a drawable.error(R.mipmap.future_studio_launcher) // will be displayed if the image cannot be loaded.crossFade().into(imageViewFade);

crossFade()方法还有一个重载方法:crossFade(int duration),毫秒单位的淡入时间,Glide默认的渐入动画时间为300毫秒

Glide加载图片不使用过渡动画dontAnimate()

Glide.with(context).load(UsageExampleListViewAdapter.eatFoodyImages[0]).placeholder(R.mipmap.ic_launcher) // can also be a drawable.error(R.mipmap.future_studio_launcher) // will be displayed if the image cannot be loaded.dontAnimate().into(imageViewFade);

不建议这样做,除非你有充足的理由,以上方法调用没有依赖关系,你可以任意设置调用

更多推荐

4.Glide使用之图片占位及过渡动画

本文发布于:2024-02-28 06:32:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1768272.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动画   图片   Glide

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!