Android: Show loading symbol in Network ImageView

Dragon picture Dragon · Apr 8, 2014 · Viewed 7.5k times · Source

I am using NetworkImageView from Volley library to load images.

But while the image takes time load from a URL I want to show a spinning/moving loading symbol in the image container.

I tried using the setDefaultImageResId() function to set a loader.gif image. But I think gif format is not supported in Android natively.

Please advice. Thanks.

Answer

manuelvsc picture manuelvsc · Jul 17, 2014

You Just need to put the NetworkImageView and the ProgressBar inside a FrameLayout or a RelativeLayout,something like this

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

     <ProgressBar
            style="?android:attr/progressBarStyle"
            android:layout_width="..."
            android:layout_height="..." />

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

</FrameLayout>

be aware that the ORDER COUNTS, make sure you put the NetworkImageView after the ProgressBar so that the NetworkImageView stays on top of the ProgressBar after loading the image.

Hope it helps!