You can use Picasso
.
Picasso
is a very popular library used in Android development that solves the whole problem of loading and processing images for you and also simplifies the display of third-party images (such as URLs). The Picasso
does from the request ( HTTP
) to the cache of this image for future use.
1) Add Picasso
to your build.gradle
and synchronize your project:
compile 'com.squareup.picasso:picasso:2.5.2'
2) If you do not, add the internet permission on your AndroidManifest.xml
:
<uses-permission android:name="android.permission.INTERNET"/>
3) Create a ImageView
any to display your image:
<ImageView
android:id="@+id/suaImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
4) Now, in your Activity
(or Fragment
or any other place that wants to display an image) just reference your ImageView
and say to Picasso
load your URL:
ImageView suaImageView = (ImageView) findViewById(R.id.suaImageView);
Picasso.with(this)
.load("http://www.dominio.com.br/imagem.jpg")
.into(suaImageView);
You also have the possibility to manipulate your image, for example:
Picasso.with(context)
.load(url)
//Definindo uma resolução para sua imagem
.resize(50, 50)
//Definindo um Scale Type para a sua imagem
.centerCrop()
.into(imageView)
Links :
Official site of Picasso
: link
GitHub
page%: link