滑动图像加载超时增加 [英] glide image loading timeout increase

查看:33
本文介绍了滑动图像加载超时增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 glide 从 URL 加载图像.当我获取图像时,我在图像视图中显示了一个加载器.一些正在获取的图像较大,因此在互联网连接缓慢时会发生超时并引发异常

I am using glide to load images from URL. While I am fetching the images I am showing a loader in the image view. Some of the images being fetched are larger and therefore in slow internet connection timeout occurs and throws exception

如何增加超时时间?

推荐答案

找了很多终于有答案了,如果你用的是volley:

After searching a lot finally got an answer, if you are using volley:

public class CustomGlide implements GlideModule {
    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
    }

    @Override
    public void registerComponents(Context context, Glide glide) {
        RequestQueue queue = new RequestQueue( // params hardcoded from Volley.newRequestQueue()
                new DiskBasedCache(new File(context.getCacheDir(), "volley")),
                new BasicNetwork(new HurlStack())) {
            @Override public <T> Request<T> add(Request<T> request) {
                request.setRetryPolicy(new DefaultRetryPolicy(10000, 1, 1));
                return super.add(request);
            }
        };
        queue.start();
        glide.register(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(queue));
    }
}

根据需要更改 DefaultRetryPolicy

在清单中:

 <meta-data
            android:name="<package-name>.CustomGlide"
            android:value="GlideModule" />

这篇关于滑动图像加载超时增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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