Loading...

Load Images Using Picasso Library in Android

Android SDK does not have a good way to get images from web and display it to android app. Almost every popular android application display images from website, web server or anywhere from the internet. To solve this problem, numbers of third party libraries are available. In this tutorial, you will learn to load images from internet using Picasso image loader library; this is one of the best and powerful image downloading and caching android library. Using this library, we can easily fill an ImageView with an image from the internet.

Picasso library have lots of features like load images from web, resizing images, cropping images, place holder and displaying error images. Picasso from Square is open source and one of the popular& easiest libraries used to download and cache images from web in android. You can also load images without using any libraries in android application, check out my tutorial: Load Image from URL (Internet) in Android.

Related:
Check Internet Connection in Android
Turn ON and OFF WiFi Connection Programmatically in Android
How to Get Current GPS Location Programmatically in Android

Android Example: View Images from Web using Picasso Image Loader Library


Create a new android project with the project name Picasso Image Loader Library. You can setup Picasso image downloader and caching library with gradle dependency or mavne. Open your app build.gradle file and add compile 'com.squareup.picasso:picasso:2.5.2' as application dependencies which will look like below.

build.gradle

XML Layout File

Open XML layout file and add ImageView with different id. Here I have added many ImageView and TextView to make look like news reader app with in LinearLayout and ScrollView. Just copy and paste following XML code in your layout file.

res/layout/activity_main.xml

Java Activity File

In java file, defile variables for different ImageView, add images URL like strings. Link to your layout image view with findViewById and load the images in ImageView from web using Picasso library like Picasso.with(this).load(imageURL4).resize(250, 200).into(image1);. Following is the complete code of java activity file.

src/MainActivity.java

Before running your application don’t forgot to add user permission android.permission.INTERNET in AndroidManifest.xml file. Android manifest file will look like below.

AndroidManifest.xml

Picasso image downloading android library offers much more than just downloading image. You can resize images, display error image when image is unable to download, rotate, place holder, transform before image is displayed in ImageView.

Picasso.with(this)
      .load("Image URL")
      .error(R.drawable.error_image) // optional
      .placeholder(R.drawable.placeholder_image) // optional
      .resize(200, 200) // optional
      .rotate(60) // optional
      .into(imageview1);

Output:


Android Example: Create a Music Player Android Application XML UI Design

You have done all things. Now, run your Load Images Using Picasso Library in Android application, you will see images in ImageView which are loaded from internet. Make sure your phone or emulator have WiFi or mobile network turned on.
Tutorial 5299814176685657049
Home item