Android image loading and caching open-source framework: Android Glide
ZookeeperAndroid image loading and caching open-source framework: Android Glide
Android Glide is an open-source third-party framework for image loading and caching. Similar to the Picasso library of Android, it is easier to use than Android Picasso. Android Glide has implemented its own internal cache policy, allowing developers to get rid of the trivial transactions of Android image loading and focus on the code of the logic business. Android Glide is easy to use. With just a few lines of simple and clear code, you can complete the functional requirements for loading and displaying most images from the Network (or local.
To use Android Glide, you must first download the Android Glide library. The Android Glide project homepage on github is as follows:
Https://github.com/bumptech/glide.
To use the actual project, you only need to download the jar package to the local libs on the Glide releases page. Glide releases page address: https://github.com/bumptech/glide/releases, in this page find the latest jar package, download and put in your own project libs, such as glide 3.6.0 library jar package: https://github.com/bumptech/glide/releases/download/v3.6.0/glide-3.6.0.jar
Next we will use it in our own project. Now we will give a detailed example to illustrate it (loading images over the network and then displaying them in ImageView ):
MainActivity. java
Import com. bumptech. glide. glide; import android. support. v7.app. actionBarActivity; import android. view. layoutInflater; import android. view. view; import android. view. viewGroup; import android. widget. arrayAdapter; import android. widget. imageView; import android. widget. listView; import android. app. activity; import android. content. context; import android. OS. bundle; public class MainActivity extends ActionBarActivi Ty {private Activity mActivity; // loads the network image from this URL. Private String img_url = "http://avatar.csdn.net/9/7/A/1_zhangphil.jpg"; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); mActivity = this; setContentView (R. layout. activity_main); ListView lv = (ListView) findViewById (R. id. listView); lv. setAdapter (new MyAdapter (this, R. layout. item);} private class MyAdapter extends ArrayAdapter {private int resource; public MyAdapter (Context context, int resource) {super (context, resource); this. resource = resource;} @ Overridepublic View getView (int position, View convertView, ViewGroup parent) {if (convertView = null) {convertView = LayoutInflater. from (mActivity ). inflate (resource, null);} ImageView iv = (ImageView) convertView. findViewById (R. id. imageView); Glide. with (mActivity ). load (img_url ). centerCrop ()/** default placeholder image, which can be set to a progress GIF image during loading */. placeholder (R. drawable. loading ). crossFade (). into (iv); return convertView;} @ Overridepublic int getCount () {// assume that the loaded data volume is large. return 10000 ;}}}
MainActivity. java requires two layout files:
Activity_main.xml
Item. xml