Loading Android Images with glide

Source: Internet
Author: User

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

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.