如何在Android Picasso中添加Loading Indicator?

时间:2015-10-06 23:13:28

标签: java android android-studio

我像这样使用Square Picasso

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

我希望Picasso加载图像时有一个旋转加载指示器。我尝试了这里发布的解决方案:

Animated loading image in picasso

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

我创建了一个动画:

<?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%"/>

并将此动画放入我的Picasso电话:

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

我的问题是动画没有运行。此外,它不是图像中间的微小加载指示器,而是加载图像被拉伸到图像的尺寸。

如何向Android Picasso添加加载指标?

1 个答案:

答案 0 :(得分: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);