How To Apply ImageLoader in Picasso
Posted By : Rahul Baboria | 29-Oct-2017
Introduction:
Android Picasso is an image loading library developed by Square Inc. Nowadays it is among most popular libraries for image caching and loading among glide, volley ,etc as it requires just one line of code . To use Picasso Library in your project add following dependency:
MAVEN:
<dependency>
<groupId>com.squareup.picasso</groupId>
<artifactId>picasso</artifactId>
<version>2.5.2</version>
</dependency>
OR
GRADLE:
compile 'com.squareup.picasso:picasso:2.5.2'
Its always been difficult to show progressbar with ImageView while loading image from internet by using image caching libraries but here we have to just pass the drawable file to placeholder . Lets take an example by creating a xml file for progress bar under src/res/drawables of your project with following code:
progress_bar_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="1080" >
<shape
android:innerRadius="17dp"
android:shape="ring"
android:thickness="3dp"
android:useLevel="false" >
<gradient
android:centerColor="#80b7b4b2"
android:centerY="0.5"
android:endColor="#f4eef0"
android:startColor="#00938c87"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>
After adding this file to your project we can show this loader rotating instead of blank interface which makes bad impression to user as user don't knows whats happening. So to show Progress (loader) we have to give placeholder location ex: progress_bar_drawable in .placeholder() in your code as shown below :
Picasso.with(activity)
.load(team.getImageUrl())
.placeholder(R.drawable.progress_bar_drawable)
.error(R.drawable.error_drawable)
.into(iv_placeholder)
Thanks.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Rahul Baboria
Rahul Baboria is having good knowledge over Android Application.