Android image loading and caching open source framework: Android Glide
Android Glide is a third-party framework for open-source picture loading and caching processing. Similar to Android's Picasso library, personal feel is better than Android Picasso. Android Glide has implemented a caching strategy within itself, allowing developers to get rid of the trivial business of Android image loading and focus on the code of logic. Android Glide Easy to use, a few lines of simple and clear code, you can complete most images from the network (or local) load, display the functional requirements.
Using Android Glide, you need to first download the Android Glide Library, Android Glide on GitHub on the project homepage:
Https://github.com/bumptech/glide.
The actual project use only needs to go to Glide's releases page to download the jar package and import it into the local libs to use directly. Glide's releases page address: https://github.com/bumptech/glide/releases, find the latest JAR package on this page, download it and put it in the Libs of your project, such as Glide Jar Package for 3.6.0 library: Https://github.com/bumptech/glide/releases/download/v3.6.0/glide-3.6.0.jar
The next step is to use it specifically in your own project, and now give a concrete example of how to use it (load the image over the network and show it 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 actionbaractivity {private Activity mactivity;//will load the network picture 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 picture, which can generally be set to a loading progress gif */.placeholder ( r.drawable.loading). Crossfade (). into (iv); return convertview;} @Overridepublic int GetCount () {//Assuming a large amount of data is loaded return 10000;}}}
Two layout files required by Mainactivity.java:
Activity_main.xml
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_ Parent " android:layout_height=" match_parent " android:orientation=" vertical "> <listview Android:id= "@+id/listview" android:layout_width= "match_parent" android:layout_height= "Wrap_content" > </ListView></LinearLayout>
Item.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:o rientation= "vertical" > <imageview android:id= "@+id/imageview" android:layout_width= "Wrap_ Content " android:layout_height=" Wrap_content "/></linearlayout>
Android images loaded with cache Open source framework: Android Glide