Android image loading and caching open-source framework: Android Glide,

Source: Internet
Author: User

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

<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:orientation="vertical" >    <ImageView        android:id="@+id/imageView"        android:layout_width="wrap_content"        android:layout_height="wrap_content" /></LinearLayout>


Related Article

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.