在毕加索animation加载图像

我有下面的代码来加载在毕加索的图像,使用可绘制的占位符来显示下载图像。 我想要的是一个animation旋转的进度条样式的微调,在图像加载的时候四处移动,就像我在大多数专业应用中看到的一样。 毕加索似乎并不支持这一点,只有静态图像可绘制。 有办法让它与毕加索合作,还是我需要做一些不同的事情?

Picasso.with(context).load(url) .placeholder(R.drawable.loading) .error(R.drawable.image_download_error) .into(view); 

如何使用毕加索占位符获取加载进度animation图像:

我使用animation旋转xml对象轻松解决了这个问题。

脚步:

progress_image.png

progress_image.png

/res/drawable/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%"/> 

毕加索loading:

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

我希望这有帮助!

我实现了进度对话框,直到图像下载,它非常简单。 以相对布局取出ImageView,并将进度加载器放在相同的图像视图中。 只应用下面的代码并处理进度对话框的可见性。

 holder.loader.setVisibility(View.VISIBLE); holder.imageView.setVisibility(View.VISIBLE); final ProgressBar progressView = holder.loader; Picasso.with(context) .load(image_url) .transform(new RoundedTransformation(15, 0)) .fit() .into(holder.imageView, new Callback() { @Override public void onSuccess() { progressView.setVisibility(View.GONE); } @Override public void onError() { // TODO Auto-generated method stub } }); } 

请享用。 🙂

毕加索遗憾地不支持animation占位符。

解决这个问题的一种方法是将ImageView放置在一个FrameLayout中,并在下面绘制animation。 这样,当毕加索加载图像时,它将加载到animation占位符的顶部,给用户预期的效果。

或者,您可以将图像加载到目标中 。 然后默认显示进度条,当调用onBitmapLoaded方法时,可以隐藏它并显示图像。 你可以在这里看到这个基本的实现

我以如下方式工作:

  1. 创build一个drawable(在互联网上find的地方),并把它放在res / drawable中:

     <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="90" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360"> <shape android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="7.0"> <gradient android:angle="0" android:centerColor="#007DD6" android:endColor="#007DD6" android:startColor="#007DD6" android:type="sweep" android:useLevel="false" /> </shape> 
  2. 在我的项目为GridView添加ProgressBar元素:

     <ProgressBar android:id="@+id/movie_item_spinner" android:layout_width="@dimen/poster_width" android:layout_height="@dimen/poster_height" android:progressDrawable="@drawable/circular_progress_bar"/> 
  3. 在适配器中添加了以下参数的目标对象,其中海报和微调器是对ImageView和ProgressBar的引用:

    // Target在ImageView上显示/隐藏ProgressBar

     final Target target = new Target() { @Override public void onPrepareLoad(Drawable drawable) { poster.setBackgroundResource(R.color.white); spinner.setVisibility(View.VISIBLE); } @Override public void onBitmapLoaded(Bitmap photo, Picasso.LoadedFrom from) { poster.setBackgroundDrawable(new BitmapDrawable(photo)); spinner.setVisibility(View.GONE); } @Override public void onBitmapFailed(Drawable drawable) { poster.setBackgroundResource(R.color.white); } }; 
  4. 结果将会像加载时一样 – circle正在旋转(对于这个截图很抱歉,但是图像显得太快了): ScreenShot

对于任何想要使用DBragion技术的人:确保你有最新版本的毕加索,否则它不会旋转。 直到我使用2.5.2版时,我才工作。

 compile 'com.squareup.picasso:picasso:2.5.2'