Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animated loading image in picasso

I have the following code to load an image in Picasso, using a drawable for the placeholder to display while the image is downloading. What I want though is an animated spinning progress bar style spinner that animates around and around while the image is loading, like I see in most professional apps. Picasso doesn't seem to support this, only static image drawables. Is there a way to get it working with Picasso or do I have to do something different?

Picasso.with(context).load(url)                                  .placeholder(R.drawable.loading)                     .error(R.drawable.image_download_error)                     .into(view); 
like image 576
NZJames Avatar asked Jul 18 '14 13:07

NZJames


People also ask

Can Picasso load GIF?

From what I know, Android doesn't have inbuilt support for GIF. So ImageView doesn't support GIF by default. I would suggest you to use Glide library for image loading, and caching since it provides support for GIF. Glide is similar to Picasso, and is sometimes considered better than Picasso.

How do you add a placeHolder in Picasso?

Picasso's fluent interface makes this very easy to do! Just call . placeHolder() with a reference to a drawable (resource) and Picasso will display that as a placeholder until your actual image is ready. Picasso .


2 Answers

How to have a loading progress animation image using Picasso placeholder:

I solved this easily using a animated-rotate xml object.

Steps:

progress_image.png

progress_image.png

/res/drawable/progress_animation.xml

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">  <item android:gravity="center">     <animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"         android:drawable="@drawable/progress_image"         android:pivotX="50%"         android:pivotY="50%" />     </item> </layer-list> 

Picasso loading:

Picasso.with( context )         .load( your_path )         .error( R.drawable.ic_error )         .placeholder( R.drawable.progress_animation )         .into( image_view ); 
like image 79
DBragion Avatar answered Oct 18 '22 08:10

DBragion


I implemented the progress dialog till the image download and its very simple. Take your ImageView in relative layout and place progress loader on same image view. Apply the below code and handle progress dialog visibility only.

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

Enjoy. :)

like image 34
Akanksha Rathore Avatar answered Oct 18 '22 10:10

Akanksha Rathore