More powerful and excellent open source framework: Android image loading and caching: Android Glide usage

Source: Internet
Author: User

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 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):

Copy the downloaded jar file here:

1  Packagecom.example.testglide;2 3 Importcom.bumptech.glide.Glide;4 5 Importandroid.app.Activity;6 ImportAndroid.content.Context;7 ImportAndroid.os.Bundle;8 ImportAndroid.view.LayoutInflater;9 ImportAndroid.view.View;Ten ImportAndroid.view.ViewGroup; One ImportAndroid.widget.ArrayAdapter; A ImportAndroid.widget.ImageView; - ImportAndroid.widget.ListView; - ImportAndroid.widget.TextView; the  -  Public classMainactivityextendsActivity { -     //Network Image Address -     PrivateString Url = "Http://img3.imgtn.bdimg.com/it/u=1183223528,3058066243&fm=21&gp=0.jpg"; +     PrivateMyadapter Mmyadapter; -  + @Override A     protected voidonCreate (Bundle savedinstancestate) { at         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); -  -ListView LV =(ListView) Findviewbyid (r.id.lv); -Mmyadapter =NewMyadapter ( This,-1); -  in Lv.setadapter (mmyadapter); -  to     } +  -     Private classMyadapterextendsArrayadapter { the         Privatecontext context; * Layoutinflater Flater; $ Panax Notoginseng          PublicMyadapter (Context context,intResource) { -             Super(context, resource); the              This. Context =context; +Flater =Layoutinflater.from (context); A         } the  + @Override -          Public intGetCount () { $             return100; $         } -  - @Override the          PublicView GetView (intposition, View Convertview, ViewGroup parent) { -             if(Convertview = =NULL)WuyiConvertview = Flater.inflate (R.layout.list,NULL); the  -ImageView IV =(ImageView) Convertview.findviewbyid (R.ID.IV); Wu  -TextView TV =(TextView) Convertview.findviewbyid (r.id.tv); About  $Tv.settext (position + ""); -             //placeholder (R.DRAWABLE.JINCHENGTU) This is loading the local picture to implement loading the network picture transition with optimized user experience -             //Crossfade (1000) set display picture fade time -  AGlide.with (context). Load (URL). Placeholder (R.DRAWABLE.JINCHENGTU). Crossfade (1000). into (iv); +  the             returnConvertview; -         } $  the     } the  the}

XML file:

1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Tools:context= "Com.example.testglide.MainActivity" >6 7     <ListView8         Android:id= "@+id/lv"9 Android:layout_width= "Wrap_content"Ten Android:layout_height= "Wrap_content" One android:layout_centerinparent= "true" /> A  - </Relativelayout>
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/iv"9 Android:layout_width= "Match_parent"Ten Android:layout_height= "Wrap_content" /> One  A     <TextView -         Android:id= "@+id/tv" - Android:layout_width= "Match_parent" the Android:layout_height= "Wrap_content" - Android:background= "#00ff00" /> -  - </LinearLayout>


Run:

More powerful and excellent open source framework: Android image loading and caching: Android Glide usage

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.