动画"/>
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使用之图片占位及过渡动画
发布评论