Image loading in Android.
There a lot libraries for loading images. Lets talk about couple of them.
- Picasso (http://square.github.io/picasso/)
dependency
dependencies { compile 'com.squareup.picasso:picasso:2.5.1' }
This library easy to use. To load image from url to ImageView you need do just one line.
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
Current library have a features which can be useful for your app:
- Image transformation
Picasso.with(context) .load(url) .resize(50, 50) .centerCrop() .into(imageView)
- Placeholder for progress and error. Useful to show some drawable if downloading failed or in progress
Picasso.with(context) .load(url) .placeholder(R.drawable.user_placeholder) .error(R.drawable.user_placeholder_error) .into(imageView);
- Using Picasso you can load images from resources, file or web
Picasso.with(context).load(R.drawable.landing_screen).into(imageView1); Picasso.with(context).load("file:///android_asset/DvpvklR.png").into(imageView2); Picasso.with(context).load(new File(...)).into(imageView3);
- Glide (https://github.com/bumptech/glide)
Current library is recommended by Google.
dependency
dependencies { compile 'com.github.bumptech.glide:glide:3.5.2' compile 'com.android.support:support-v4:22.0.0' }
Usage:
Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView);
Also Glide has a features:
Glide .with(myFragment) .load(url) .centerCrop() .placeholder(R.drawable.loading_spinner) .crossFade() .into(myImageView);
I use Glide because:
1. Faster than Picaso
2. Have better “.with()” method. Glide.with(this) can take Context, Fragment, Activity, etc.
Currently Glide better Image loader library.
Awaiting your comments.
1 Comment
Sergii · 19 May, 2016 at 09:24
Speed: Picasso.fit() does what Glide does by default.
Fragments, loaders, volley, dagger 2 are also recommended by Google.