小编use*_*346的帖子

使用Android Picasso将图像预加载到内存/磁盘中

我可以在展示之前用Picasso下载图像吗?我想先缓存图像.

示例场景:用户单击按钮,查看进度条,图像加载完成后,用户可以在屏幕上看到图像.

我尝试使用"get"方法加载图像,但是没有缓存图像.

Thread thread = new Thread()
{
    @Override
    public void run() {
        try {
            Picasso picasso = PicassoOwnCache.with(getApplicationContext());
            RequestCreator picassoRequest;
            for (String imgUrl : imagesUrls) {
                picassoRequest = picasso.load(imgUrl);
                picassoRequest.get();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
};

thread.start();
Run Code Online (Sandbox Code Playgroud)

这是我的毕加索单身课程

public class PicassoOwnCache {
    static Picasso singleton = null;
    static Cache cache = null;

    public static Picasso with(int cacheSize, Context context) {
        if (singleton == null) {
            int maxSize = calculateMemoryCacheSize(context);
            cache = new LruCache(cacheSize <= …
Run Code Online (Sandbox Code Playgroud)

android picasso

17
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×1

picasso ×1