如何在Android Picasso中添加加载指示器?

3
我像这样使用Square Picasso:Square Picasso
  Picasso.with(context)
      .load(url)
      .centerCrop()
      .fit()
      .into(imageView);

我希望当 Picasso 加载图像时,能够有一个旋转的加载指示器。我尝试了这里发布的解决方案:Picasso 中的动画加载图像在 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中添加加载指示器?


使用不同形式的动画可绘制对象,例如AnimationDrawable。"此外,它不是图像中间的小型加载指示器,而是将加载图像拉伸到图像的尺寸" - 您需要设置可绘制对象以具有所需的填充。可能会在animated-rotate中使用该属性(我没有看到或使用过); 对于AnimationDrawable,您提供帧,因此应将填充放入帧图像本身中。 - CommonsWare
1
你能否在回答中提供一个示例? - Michael
1个回答

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);

这似乎没有动画效果。 - Carson Holzheimer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接