I. Overview
Glide is a very good picture buffer tool on the Android side, and overall, he has the following advantages
- Easy to use
- High degree of self-adaptation
- Support for common image formats such as jpg,png, etc.
- Support multiple data sources, network, local, resource, assets, etc.
- Efficient caching strategy, support memory and disk picture cache policy, the default bitmap format is reduced by at least half of rgb_565 RAM usage
- Lifecycle integration automates management of requests based on the Activity/fragment life cycle
- Efficient processing bitmap uses bitmap pool to enable bitmap reuse, proactively calls Recycel reclaim bitmap that need to be recycled, reducing pressure on system recycling
Ii. Methods of Use
Step 1, add the following code in the Build.gradle dependencies:
1 compile "com.github.bumptech.glide:glide:3.7.0"
Step 2, use directly in the code:
1 Fun Onclick_loadimageview (v:view) {2 glide.with (this)3 . Load (Img_uri) 4 . Placeholder (r.drawable.loading)5 . Error (R.drawable.error)6 . Into (IMG)78 }
Note that because the Img_uri in this place is a network picture, we also need to set up network access in Androidmanfiest
1 <uses-permission android:name= "Android.permission.INTERNET" ></uses-permission>
Iii. Summary of Glide methods
In general, glide common methods are as follows
- With () is related to the life cycle. So this time using activity or application context needs to be considered clearly
- Load Loading resource path
- Into the imageview that the image is loaded into
The above three methods are the most basic methods, the following are some extension methods
- Placeholder Loading pictures
- The bitmap that appears after error loading fails
- Thumbnail thumbnail support.
- Override to set Load dimensions
- Asgif cast to GIF
- Diskcachestrategy Setting the picture cache policy
- Transform transduction, such as the realization of fillet pictures, etc.
All the code in this article has been uploaded to Github:https://github.com/yanyojun/dangerouspermission
Reprint please specify the original address: http://www.cnblogs.com/yanyojun/p/8016294.html
Loading Android Images with glide