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);
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.
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 .
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
/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 );
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. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With