毕加索(Picasso)花时间加载图像 [英] Picasso Taking time to load images

查看:81
本文介绍了毕加索(Picasso)花时间加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用毕加索在我的回收站视图适配器中加载图像,但是要花费很多时间来加载图像.这是我打电话给毕加索加载图像的电话.

I'm using picasso to load images in my recycler view adaper but it is taking to much time to load image. Here is my call to load image with picasso.

Picasso.with(hostActivity).load("ImageUrl").fit().centerCrop().into(holder.ImageView);

如果我对asynctask任务执行相同的操作,则会立即加载图像.

If I do same thing with asynctask task, image loaded instantly.

我做错什么了吗?

谢谢.

推荐答案

fit()需要等待ImageView的大小确定之后,才能对图像进行大小匹配,并且大小不能计算,直到布局通过结束为止.如果您能够预测合理的宽度和高度值,则使用resize()可能会更快地得到结果.

fit() needs to wait for the size of the ImageView to be determined before it can size the image to match, and the size can't be calculated until the end of the layout pass. You might get quicker results by using resize() if you are able to predict reasonable width and height values.

您可能还想看看 Glide 库,因为它采用了一种不同的缓存方法,可以在某些情况下比Picasso更快,例如,它不是缓存完整尺寸的图像,而是缓存了调整大小的图像.但是,这两个库都有很多优缺点.尽管语法非常相似,但某些可在毕加索使用的功能在Glide中将无法使用,反之亦然.

You might also want to look at the Glide library as it takes a different approach to caching that can be quicker than Picasso in some cases, for example instead of caching full size images it caches the resized ones. However, there are many pros and cons to both libraries; although the syntaxes are very similar, some things that work in Picasso will not work in Glide, and vice versa.

这篇关于毕加索(Picasso)花时间加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆