通过滑行检查图像是否已加载图像(URL) [英] check image is loaded image(url) by glide

查看:63
本文介绍了通过滑行检查图像是否已加载图像(URL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的android应用中,我有4个网址可显示一张图片.检查网址1是否损坏,然后以相同的方式转到网址2,直到结束. 我使用 Glide 4.3.1 加载像这样的图像:

In my android app i have 4 url for one single image. to check if url 1 is broken then go to url 2 and the same way until the end. i using Glide 4.3.1 for loading image like this :

private int checkAndShow4Image(Context context, View view, int img_id, String img_url) {
    try {            
        GlideApp
                .with(context)
                .load(img_url)
                .diskCacheStrategy(DiskCacheStrategy.DATA)
                .error(R.drawable.ic_broken_image)
                .fallback(R.drawable.ic_broken_image)
                .transition(DrawableTransitionOptions.withCrossFade())
                .into((ImageView) view.findViewById(img_id));

    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
    return 0;
}

该方法在完全加载之前返回.等待的最佳方法是什么?

the method is returning before of complete loading. what is the best way for waiting for do it?

推荐答案

Glide使用异步方式显示图像,尝试使用回调来知道图像何时完成或失败:

Glide use asynchronous way to display the image, try to use a callback to know when the image is completed or failed:

.listener(new RequestListener<Drawable>() {
                                @Override
                                public boolean onLoadFailed(@android.support.annotation.Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {

                                    return false;
                                }

                                @Override
                                public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                                    return false;
                                }
                            }
                    )
                    .into(view);

这篇关于通过滑行检查图像是否已加载图像(URL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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