【问题标题】:How to add Loading Indicator to Android Picasso?如何将加载指示器添加到 Android Picasso?
【发布时间】:2015-10-06 23:13:28
【问题描述】:

我这样使用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%"/>

并将这个动画放在我的Picassocall 中:

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

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

如何向 Android Picasso 添加加载指示器?

【问题讨论】:

  • 使用不同形式的动画drawable,例如an AnimationDrawable。 “而且它不是图像中间的微小加载指示器,而是加载图像被拉伸到图像的尺寸” - 您需要设置您的可绘制对象以根据需要设置填充。 animated-rotate 可能有它的属性(我没有看到或使用过);对于AnimationDrawable,您提供框架,因此会将填充放在框架图像本身中。
  • 能否请您在答案中发布一个示例?

标签: java android android-studio


【解决方案1】:

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

【讨论】:

  • 这似乎没有动画
猜你喜欢
  • 2015-09-28
  • 1970-01-01
  • 2016-05-22
  • 2012-03-12
  • 2023-01-29
  • 2013-10-20
  • 2013-10-30
  • 1970-01-01
  • 2023-03-21
相关资源
最近更新 更多