Image loading and caching weapon--third party open source--Glide

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.