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
1 Importcom.bumptech.glide.Glide;2 3 Importandroid.support.v7.app.ActionBarActivity;4 ImportAndroid.view.LayoutInflater;5 ImportAndroid.view.View;6 ImportAndroid.view.ViewGroup;7 ImportAndroid.widget.ArrayAdapter;8 ImportAndroid.widget.ImageView;9 ImportAndroid.widget.ListView;Ten Importandroid.app.Activity; One ImportAndroid.content.Context; A ImportAndroid.os.Bundle; - - Public classMainactivityextendsactionbaractivity { the - PrivateActivity mactivity; - //the network picture will be loaded from this URL. - PrivateString Img_url = "Http://img4.duitang.com/uploads/item/201306/10/20130610100354_3WrWN.gif"; + - @Override + protected voidonCreate (Bundle savedinstancestate) { A Super. OnCreate (savedinstancestate); atMactivity = This; - - Setcontentview (r.layout.activity_main); - -ListView LV =(ListView) Findviewbyid (R.id.listview); -Lv.setadapter (NewMyadapter ( This, R.layout.item)); in } - to Private classMyadapterextendsArrayadapter { + - Private intresource; the * PublicMyadapter (Context context,intResource) { $ Super(context, resource);Panax Notoginseng This. Resource =resource; - } the + @Override A PublicView GetView (intposition, View Convertview, ViewGroup parent) { the if(Convertview = =NULL) { +Convertview =Layoutinflater.from (mactivity). Inflate (Resource, - NULL); $ } $ -ImageView IV =(ImageView) Convertview.findviewbyid (R.id.imageview); - the Glide.with (mactivity). Load (Img_url). Centercrop () - /*Wuyi * The default placeholder image, can be set to a loading progress gif, placeholder display loading picture, Crossdade (time) represents the fade the */ - . Placeholder (r.drawable.loading). Crossfade (). into (iv); Wu - returnConvertview; About } $ - @Override - Public intGetCount () { - //assuming a large amount of data is loaded A return10000; + } the } -}
Activity_main.xml:
1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Android:layout_width= "Match_parent"3 Android:layout_height= "Match_parent"4 android:orientation= "vertical" >5 6 <ListView7 Android:id= "@+id/listview"8 Android:layout_width= "Match_parent"9 Android:layout_height= "Wrap_content" >Ten </ListView> One A </LinearLayout>
Item.xml
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 android:orientation= "vertical" >6 7 <ImageView8 Android:id= "@+id/imageview"9 Android:layout_width= "Wrap_content"Ten Android:layout_height= "Wrap_content" /> One A </LinearLayout>
Image loading and caching weapon--third party open source--Glide