Android: show download symbol in Network ImageView

I am using NetworkImageView from the Volley library to upload images.

But while the image is taking temporary load from the url, I want to show the rotation / move symbol in the image container.

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

I ask for advice. Thank.

+4
source share
3 answers

You just need to put NetworkImageViewboth ProgressBarinside FrameLayoutor RelativeLayoutsomething 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>

, , NetworkImageView ProgressBar, NetworkImageView ProgressBar .

, !

+9

. gif Android . , /. .

NetworkImageView, ImageView, ImageLoader. , , . , RequestQueue ImageLoader. , .

:

// ** code in init the progress wheel **

imageLoader.get(url, new ImageListener() {
    @Override
    public void onResponse(ImageContainer response, boolean isImmediate) {
        if (response != null) {
            Bitmap bitmap = response.getBitmap();
            if (bitmap != null) {
                // ** code to turn off the progress wheel **
                // ** code to use the bitmap in your imageview **
            }

    @Override
    public void onErrorResponse(VolleyError error) {
        // ** code to handle errors **
    }
});
+3

I did this with animation. Here are the steps:

Animation drawable ic_sync_drawable.xml:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/selected"
    android:oneshot="false">
    <item
        android:drawable="@drawable/ic_popup_sync_1"
        android:duration="50" />
    <item
        android:drawable="@drawable/ic_popup_sync_2"
        android:duration="50" />
    <item
        android:drawable="@drawable/ic_popup_sync_3"
        android:duration="50" />
    <item
        android:drawable="@drawable/ic_popup_sync_4"
        android:duration="50" />
    <item
        android:drawable="@drawable/ic_popup_sync_5"
        android:duration="50" />
    <item
        android:drawable="@drawable/ic_popup_sync_6"
        android:duration="50" />
</animation-list>

Now in java code I use ImageView:

Drawable drawable = getContext().getResources().getDrawable(R.drawable.ic_sync_drawable);
ImageView imageView = new ImageView(getContext());
imageView.setImageDrawable(drawable);
imageLoader.get(imageurl, ImageLoader.getImageListener(imageView, 0, 0));
ViewFlipper.addView(imageView);
//start animation
 AnimationDrawable frameAnimation = (AnimationDrawable) drawable;
frameAnimation.start();
+1
source

Source: https://habr.com/ru/post/1535641/


All Articles