Add Spinning progress for ImageView in Android

549 views Asked by At

I have an ImageView in which i want to show ProgressBar while loading the image from URL. To load image i am using VolleyPlus library. Here is the code to load image:

DiskLruBasedCache.ImageCacheParams cacheParams = new DiskLruBasedCache.ImageCacheParams(getApplicationContext(), "CacheDirectory");
cacheParams.setMemCacheSizePercent(0.5f);
SimpleImageLoader mImageFetcher = new SimpleImageLoader(getApplicationContext(), R.drawable.progress, cacheParams);
mImageFetcher.get(image_url, imgView);

Now my problem is Can i make drawable to make ProgressBar (R.drawable.progress) within ImageView.

1

There are 1 answers

0
Mostafa Gazar On

You use setDefaultImageResId to an image to show during loading and if failed but you will not be able to use a view though. You can however use FrameLayout and ProgressBar behind NetworkImageView to show spinning progress while loading.

In case of successful download you do not have to do anything thing because Android should draw the progress view because it is hidden, in case of failure you will have to take it off.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

    <com.android.volley.toolbox.NetworkImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop" />

</FrameLayout>