picasso的使用
来源:互联网 发布:淘宝上外贸是正品吗 编辑:程序博客网 时间:2024/06/05 23:31
导入方法: 下载 picasso.jar 导入libs文件夹下即可。 AS配置: compile 'com.squareup.picasso:picasso:2.5.2'1.一般使用格式: 支持本地资源图片(drawable文件夹下),文件,资产(assets文件夹下),内容提供商(contacts photo),网页链接作为图片来源。
推荐一篇相关的博客:Picasso框架实战演练
//在下载出错的图像被设置前,Picasso会尝试三次请求,三次都失败才会显示errorPicasso.with(context) .load(url) //.fit() //让图片的宽高恰好等于组件宽高.前提是组件必须有大小使用了fit方法,就不能调用resize //.resize(80, 80).centerCrop() | .centerInside() //图片裁剪 //.resizeDimen(R.dimen.width,R.dimen.height) //.transform(new CropSquareTransformation()) //自定义实现裁剪 //.placeholder(R.drawable.user_placeholder) //下载完成前的图像 //.error(R.drawable.user_placeholder_error) //出错时的图像 .into(imageView);//要想显示不拉伸的图,组件可设置scaleType=centerInsideclass CropSquareTransformation implements Transformation { @Override public Bitmap transform(Bitmap source) { //自定义图片裁剪 int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap result = Bitmap.createBitmap(source, x, y, size, size); if (result != source) { source.recycle(); } return result; } @Override public String key() { return "square()"; }}//通常在滑动列表的时候需要暂停请求,例如在RecyclerView滑动时监听,处理不同的表现:public class RecyclerViewScrollListener implements AbsListView.OnScrollListener { private final Context context; public RecyclerViewScrollListener(Context context) { this.context = context; } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { final Picasso picasso = Picasso.with(context); if (scrollState == SCROLL_STATE_IDLE || scrollState == SCROLL_STATE_TOUCH_SCROLL) { picasso.resumeTag(context); } else { picasso.pauseTag(context); } } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // Do nothing. }}2.调试使用 调用setIndicatorsEnabled(true);不同来源的图片可自动在左上角显示一个不同颜色的三角形。如:红色--网络,黄色--磁盘缓存,绿色--内存。
推荐一篇相关的博客:Picasso框架实战演练
0 0
- picasso框架的使用
- Picasso的使用
- picasso的使用
- Picasso框架的使用
- Picasso的使用
- Picasso的使用
- Picasso的使用
- Picasso的基本使用
- Picasso的使用
- Picasso的使用
- Picasso框架的使用
- Picasso的基本使用
- Picasso框架的使用
- Picasso的使用总结
- Picasso的详细使用
- Picasso的使用
- Picasso的使用
- Picasso的简单使用
- View动画(补间动画)
- Quick Leaner学Python
- Android6.0以后,如何获取当前运行的app
- Android实现IOS向右滑动退出当前Activity
- java源码分析(1)-Integer
- picasso的使用
- I People Counting
- Centos 6.5 安装Oracle 12C RAC
- Leetcode Reverse String 344
- 服务的启动、停止和与活动的通信
- java.lang.Class.isPrimitive()方法实例
- 电荷泵式开关电源的基本电路
- SQL中的cast和convert的用法和区别
- 党课心得一(杂谈)