How to add picasso library in android studio?

Before getting into picasso library example, we should know about picasso. Picasso is image processing library and developed by Square Inc. In older days we used to write lengthy of codes to grab image from server or do process., to optimize the process picasso introduced.

This example demonstrate about how to integrate picasso library in android studio.

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.

Step 2 − Add the following code in build.gradle.

apply plugin: ''
android {
   compileSdkVersion 28
   defaultConfig {
      applicationId "com.example.andy.myapplication"
      minSdkVersion 15
      targetSdkVersion 28
      versionCode 1
      versionName "1.0"
      testInstrumentationRunner ""
   buildTypes {
      release {
         minifyEnabled false
         proguardFiles getDefaultProguardFile('proguard-android.txt'), ''  
dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation ''
   implementation ''
   testImplementation 'junit:junit:4.12'
   implementation 'com.squareup.picasso3:picasso:2.71828'
   androidTestImplementation ''
   androidTestImplementation ''

Step 3 − Add the following code to res/layout/activity_main.xml.

<?xml version = "1.0" encoding = "utf-8"?>
   xmlns:android = "" xmlns:tools = "" android:layout_width = "match_parent"
   android:layout_height = "match_parent">
   android:layout_width = "match_parent"
   android:layout_height = "match_parent"
   android:gravity = "center"
   android:orientation = "vertical">
      android:id = "@+id/imageView"
      android:layout_width = "wrap_content"
      android:layout_height = "wrap_content" />

Step 4 − Add the following code to src/

package com.example.andy.myapplication;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.Toast;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
public class MainActivity extends AppCompatActivity {
   protected void onCreate(Bundle savedInstanceState) {
      ImageView imageView=findViewById(;
      .resize(400, 400)
      .into(imageView, new Callback() {
         public void onSuccess() {
            Toast.makeText(getApplicationContext(), "Fetched image from internet", Toast.LENGTH_SHORT).show();
         public void onError() {
            Toast.makeText(getApplicationContext(), "An error occurred", Toast.LENGTH_SHORT).show();

In the above code we have so many methods are associate with picasso as shown below.

  • with() − we have to pass context for the piasso library

  • load() − what we want to load in picass we have to give that path either it is local directory or internet source

  • resize() − if you want to resize your image, you can do that with certain width and height.

  • centercrop() − you can do center crop to your image view.

  • rotate() − you can rotate your image as 0 to 360 degreees

  • into() − In which view you want to show, we have to give imageview paths and there are two call backs are available as shown below

  • onSuccess() − if image is successfully downloaded, you can do any action.

  • onError() − if image is not successfully downloaded, you can do any action.

Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of your project's activity files and click Run  Play Icon icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen.

Logo Resize

Now you can observe the above image, The above image is cropped according to size which we have given in resize(). now we have removed the centerCrop() and resize method, it will show image with default size as shown below.

TP Logo

Click here to download the project code

Updated on: 27-Jan-2020


Kickstart Your Career

Get certified by completing the course

Get Started