简体   繁体   中英

How to load image by image using Glide Library?

I have an application contains a range of image appears by links using glide library, my app takes a long time to load all images so is it possible to load image by image ( one by one ).

Glide.with(context)
    .load(imageId.get(position))
    .diskCacheStrategy(DiskCacheStrategy.ALL)
    .priority(Priority.HIGH)
    .listener(new RequestListener<String, GlideDrawable>() {
        @Override
        public boolean onException(Exception e, String  model, Target<GlideDrawable> target, boolean isFirstResource) {   
            return false;
        }
        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            progressBar.setVisibility(View.GONE);
            return false;
        }
    })
    .into(holder.CategoryImage);

Try this

Glide.with(context)
        .load(imageId.get(position))
        .diskCacheStrategy(DiskCacheStrategy.ALL)
        .priority(Priority.HIGH)
        .listener(new RequestListener<String, GlideDrawable>() {
            @Override
            public boolean onException(Exception e, String  model, Target<GlideDrawable> target, boolean isFirstResource) {   
                   return false;
            }
            @Override
            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                progressBar.setVisibility(View.GONE);
                return false;
            }
        })
        .thumbnail(0.1f) // this will do the trick
        .into(holder.CategoryImage);

if it does not work, Try this way,

Glide.with(context)
        .load(imageId.get(position))
        .diskCacheStrategy(DiskCacheStrategy.ALL)
        .priority(Priority.HIGH)
        .override(100,100)
        .listener(new RequestListener<String, GlideDrawable>() {
            @Override
            public boolean onException(Exception e, String  model, Target<GlideDrawable> target, boolean isFirstResource) {   
                   return false;
            }
            @Override
            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                progressBar.setVisibility(View.GONE);
                Glide.with(context).load(imageId.get(position))
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .priority(Priority.HIGH)
                    .into(holder.CategoryImage);
                return false;
            }
        })
        .into(holder.CategoryImage);

Use this code :

 Glide.with(this)
            .load(sharePref.getUserImage())
            .asBitmap()
            //.centerCrop()
            .placeholder(R.drawable.ic_account_circle_black_48dp)     // .placeholder(R.drawable.user)
            .into(new BitmapImageViewTarget(user_Image) {
                @Override
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable circularBitmapDrawable =
                            RoundedBitmapDrawableFactory.create(getResources(), resource);
                    circularBitmapDrawable.setCircular(true);
                    user_Image.setImageDrawable(circularBitmapDrawable);
                }
            });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM