码迷,mamicode.com
首页 > 其他好文 > 详细

Glede学习之路

时间:2016-11-12 11:47:07      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:hold   strong   大量   nbsp   资源   ora   网络图   代码   back   

1、为什么要使用Gilde

    因为android原生的加载图片的方式不够人性化,在内存优化、缓存处理和网络加载方面,需要开发者付出大量的精力和时间,而glide在这些方面都做了很好的处理和封装,使我们可以写少量的代码就能快速高效地完成需求,提高了我们的开发效率

 

2、简单的加载图片

1、从uri中加载图片

  1. Glide.with(this)
  2.         .load(Uri.parse("http://10.0.3.2:8080/pic/nami (1).jpg"))
  3.         .into(mIv1);

2.从资源中加载

  1. Glide.with(this)
  2.         .load(R.drawable.hayin)
  3.         .into(mIv2);

3、从文件中加载

  1. File file = new File(Environment.getExternalStorageDirectory(),"Download/xun.jpg");
  2. Glide.with(this)
  3.         .load(file)
  4.         .into(mIv3);

 

3、在ListAdapter(ListView, GridView)中的使用Glide加载图片

    跟简单的加载图片没有什么不同

 

4、placeholder(…)---设置一个正在加载的占位符

    就是当正在加载网络图片过程中,显示出来的图片

  1. Glide.with(mContext)
  2.         .load(url)
  3.         .placeholder(R.drawable.loading)
  4.         .into(imageView);

 

5、error(…)设置加载错误的占位符

    就是当加载网络图片失败显示出来的图片

  1. Glide
  2.     .with(context)
  3.     .load("http://futurestud.io/non_existing_image.png")
  4.     .placeholder(R.drawable.error) // can also be a drawable
  5.     .error(R.mipmap.future_studio_launcher) // will be displayed if the image cannot be loaded
  6.     .into(imageViewError);

 

6、crossFade()---淡入淡出功能

当ImageView中的图片变为另一张时,这个方法可以使这种变化变得平滑,比如从占位符图片到显示出加载好的图片的过程

从glide3.6.1开始这个方法是默认调用的

  1. Glide
  2.     .with(context)
  3.     .load(UsageExampleListViewAdapter.eatFoodyImages[0])
  4.     .placeholder(R.mipmap.ic_launcher) // can also be a drawable
  5.     .error(R.mipmap.future_studio_launcher) // will be displayed if the image cannot be loaded
  6.     .crossFade()//glide3.6.1之后这个方法是默认调用的,即不写也行
  7.     .into(imageViewFade);

 

7、dontAnimate()---取消淡入淡出功能

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

 

 

 

Glede学习之路

标签:hold   strong   大量   nbsp   资源   ora   网络图   代码   back   

原文地址:http://www.cnblogs.com/zq19910303/p/6056246.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!