3

I use Square Picasso like this:

  Picasso.with(context)
      .load(url)
      .centerCrop()
      .fit()
      .into(imageView);

I want to have a rotation loading indicator while Picasso loads the image. I tried the solutions posted here:

Animated loading image in picasso

Show an "Loading..." image while background loading of image with Picasso

I created an animation:

<?xml version="1.0" encoding="utf-8"?>

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

and put this animation inside my Picassocall:

Picasso.with( context )
        .load( your_path )
        .error( R.drawable.ic_error )
        .placeholder( R.drawable.progress_animation )
        .into( image_view );

My problem is that the animation is not running. Also it is not a tiny loading indicator in the middle of the image, instead the loading image is stretched to the dimensions of the image.

How can I add a Loading Indicator to Android Picasso?

Community
  • 1
  • 1
Michael
  • 32,527
  • 49
  • 210
  • 370
  • Use a different form of animated drawable, such as [an `AnimationDrawable`](http://developer.android.com/guide/topics/graphics/drawable-animation.html). "Also it is not a tiny loading indicator in the middle of the image, instead the loading image is stretched to the dimensions of the image" -- you would need to set up your drawable to have padding as desired. There might be attributes for that with `animated-rotate` (I haven't seen or used that); for `AnimationDrawable`, you supply the frames and so would put the padding in the frame images themselves. – CommonsWare Oct 06 '15 at 23:38
  • 1
    Could you please post an example in an answer? – Michael Oct 06 '15 at 23:40

1 Answers1

2

progress_animation.xml -

    <?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/progress_image"
android:pivotX="50%"
android:pivotY="50%"/>

and use picasso like this - 

Picasso.with(this).load(imageString).placeholder( R.drawable.progress_animation ).into(imageView);
Mandeep Kumar
  • 776
  • 4
  • 18