java - 如何将加载指示器添加到 Android Picasso?

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

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

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

最佳答案

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

关于java - 如何将加载指示器添加到 Android Picasso?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32981276/

相关文章:

android - 如何在 chenge 构建变体 flavor 时更改自动 settings.gradle

Android Annotations/Gradle/Android Studio 构建问题

java - 我在 android studio 中做了一个测验,我只想显示 15 个问题,但我总共有 100 个问题?我有 SQLite,但我不明白它是如何工作的

java.sql.SQLException : ORA-01000: maximum open cursors exceeded

android - 不幸的是,应用程序已停止 - 在 if-else 条件下显示 Toast

android - BlurBehind - 在 Android Studio 依赖项中找不到

java - 在 libgdx 中更改为游戏结束屏幕

java - 尝试将数据写入 JAVA 中的多个工作表时 XLSX 文件损坏

java异常: connection reset by peer: socket write error

java - Java 接口(interface)中返回类或子类类型的方法