Android 图片加载问题
2014-05-13 14:25
465 查看
1、Picasso (http://square.github.io/picasso/)
Picasso是一个用于Android平台上的下载和缓存图片的项目。它有许多定制选项,如何处理下载图片(包括调整和裁剪,以及提供一个接口让你随自己心意将图片转换成圆角等)。Picasso将要下载的图片(如果没有缓存)并将它负载到指定的目标,转换图片以适合所显示的ImageView,来减少内存消耗。
Adapter re-use is automatically detected and the previous download canceled.
You can also specify custom transformations for more advanced effects.
Pass an instance of this class to the
A request will be retried three times before the error placeholder is shown.
<dependency> <groupId>com.squareup.picasso</groupId>
<artifactId>picasso</artifactId>
<
9a2e
;version>2.2.0</version></dependency>
Picasso是一个用于Android平台上的下载和缓存图片的项目。它有许多定制选项,如何处理下载图片(包括调整和裁剪,以及提供一个接口让你随自己心意将图片转换成圆角等)。Picasso将要下载的图片(如果没有缓存)并将它负载到指定的目标,转换图片以适合所显示的ImageView,来减少内存消耗。
Adapter re-use is automatically detected and the previous download canceled.
@Override public void getView(int position, View convertView, ViewGroup parent) { SquaredImageView view = (SquaredImageView) convertView; if (view == null) { view = new SquaredImageView(context); } String url = getItem(position); Picasso.with(context).load(url).into(view); }
Image Transformations
Transform images to better fit into layouts and to reduce memory size.Picasso.with(context) .load(url) .resize(50, 50) .centerCrop() .into(imageView)
You can also specify custom transformations for more advanced effects.
public class 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()"; } }
Pass an instance of this class to the
transformmethod.
Place Holders
Picasso supports both download and error placeholders as optional features.Picasso.with(context) .load(url) .placeholder(R.drawable.user_placeholder) .error(R.drawable.user_placeholder_error) .into(imageView);
A request will be retried three times before the error placeholder is shown.
Resource Loading
Resources, assets, files, content providers are all supported as image sources.Picasso.with(context).load(R.drawable.landing_screen).into(imageView1); Picasso.with(context).load(new File(...)).into(imageView2);
<dependency> <groupId>com.squareup.picasso</groupId>
<artifactId>picasso</artifactId>
<
9a2e
;version>2.2.0</version></dependency>
相关文章推荐
- android 中解决gridview 等加载大图片出现oom的问题
- Android相册解决加载大量图片卡顿问题
- 解决Android加载图片时内存溢出的问题
- android 图片加载库 Glide 的使用过程中出现的问题
- android 加载大图片适配问题解决方案
- Android 加载图片时的内存问题
- Android ListView异步加载图片乱序问题,原因分析及解决方案
- Android有效解决加载大图片时内存溢出的问题
- 解决Android加载图片时内存溢出的问题
- Android ListView异步加载图片乱序问题,原因分析及解决方案
- Android有效解决加载大图片内存溢出问题及优化虚拟机内存
- Android使用BitmapFactory.Options解决加载大图片内存溢出问题
- Android完美解决GridView异步加载图片和加载大量图片时出现Out Of Memory问题
- Android ListView异步加载图片乱序问题,原因分析及解决方案
- Android中ListView异步加载图片错位、重复、闪烁问题分析及解决方案
- Android内存溢出整理总结 OOM(Out Of Memory) 加载的图片太多或图片过大时经常出现OOM问题
- Android中处理加载图片时内存溢出问题
- Android有效解决加载大图片时内存溢出的问题
- 连载 1 - 深入讨论 Android 关于高效显示图片的问题 - 如何高效的加载大位图
- Android有效解决加载大图片时内存溢出的问题