Helpme
Helpme

Reputation: 133

Update the progress bar with glide

i want to replace a normal circular progress bar with a progressive.

      <LinearLayout android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/image"/>

            <ProgressBar
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/pb"
                android:visibility="visible"
                android:max="100"
                style="@android:style/Widget.ProgressBar.Horizontal"/>

        </LinearLayout>

I load this image with Glide:

  Glide.with(getApplicationContext())
  ....
 .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;
                        }

How can I increase the progress bar with glide, before the final result?

Upvotes: 0

Views: 3160

Answers (2)

Amir Ziarati
Amir Ziarati

Reputation: 15087

you need to use an interceptor for the okhttpclient of glide. here is a link showing how to do that:

sample for showing progress bar with glide

Upvotes: 0

Divyesh Patel
Divyesh Patel

Reputation: 2576

If you want to show progress bar until image is downloaded from server, then u can use placeholder:

Glide.with(context)
                    .load("IMAGE URL")
                    .placeholder(R.drawable.animview)
                    .error(R.drawable.search)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(holder.iv);

For animview.xml:

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/spinner"
    android:pivotX="50%"
    android:pivotY="50%"/>

use drawable image like progressbar.

Upvotes: 1

Related Questions