本文介绍了在慢速连接上使用毕加索加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Picasso加载列表视图的图像.问题是互联网连接速度慢.如何在毕加索中更改加载超时时间?
I am using Picasso to load images for a listview.The problem is internet connection is slow.How can I change load timeout time in Picasso?
我的代码是:
Picasso.with(context)
.load(MainActivity.WEBSITE + book_item.Image)
.resize(final_thumb_width, final_thumb_height)
.into(new PicassoTarget(book_item,item.img, item.title));
推荐答案
您可以在MainActivity的onCreate(或想要创建Picasso Builder的任何地方)中尝试这样的操作
You could possibly try something like this in your MainActivity's onCreate (or whereever you want to create the Picasso Builder
Picasso picasso;
OkHttpClient okHttpClient;
okHttpClient = new OkHttpClient();
okHttpClient.setConnectTimeout(10, TimeUnit.SECONDS);
picasso = new Picasso.Builder(this)
.downloader(new OkHttpDownloader(okHttpClient))
.build();
那应该给毕加索一个十秒钟的超时时间.根据您的需要进行配置.
That should give Picasso a timeout of ten seconds. Configure it to your needs.
完全公开:我不使用超时.我刚刚在API中注意到了这一点.这可能是完全错误的.
Full Disclosure: I don't use a timeout. I just noticed this in the API. This may be completely wrong lol.
这篇关于在慢速连接上使用毕加索加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!