图片加载库Glide的封装工具类,方便以后使用
直接上源码。注释得已经很清晰了,直接调用即可。
package com.liuguilin.lovewallpaper.utils;
/*
* Created by 火龙裸先生 on 2017/3/3 0003.
*/ import android.content.Context;
import android.widget.ImageView; import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.SimpleTarget; public class GlideUtils { /**
* Glide特点
* 使用简单
* 可配置度高,自适应程度高
* 支持常见图片格式 Jpg png gif webp
* 支持多种数据源 网络、本地、资源、Assets 等
* 高效缓存策略 支持Memory和Disk图片缓存 默认Bitmap格式采用RGB_565内存使用至少减少一半
* 生命周期集成 根据Activity/Fragment生命周期自动管理请求
* 高效处理Bitmap 使用Bitmap Pool使Bitmap复用,主动调用recycle回收需要回收的Bitmap,减小系统回收压力
* 这里默认支持Context,Glide支持Context,Activity,Fragment,FragmentActivity
*/ //默认加载
public static void loadImageView(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).into(mImageView);
} //加载指定大小
public static void loadImageViewSize(Context mContext, String path, int width, int height, ImageView mImageView) {
Glide.with(mContext).load(path).override(width, height).into(mImageView);
} //填充
public static void loadImageCrop(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).into(mImageView);
} //设置加载中以及加载失败图片
public static void loadImageViewLoding(Context mContext, String path, ImageView mImageView, int lodingImage, int errorImageView) {
Glide.with(mContext).load(path).placeholder(lodingImage).error(errorImageView).into(mImageView);
} //设置加载中以及加载失败图片并且指定大小
public static void loadImageViewLodingSize(Context mContext, String path, int width, int height, ImageView mImageView, int lodingImage, int errorImageView) {
Glide.with(mContext).load(path).override(width, height).placeholder(lodingImage).error(errorImageView).into(mImageView);
} //设置跳过内存缓存
public static void loadImageViewCache(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).skipMemoryCache(true).into(mImageView);
} //设置下载优先级
public static void loadImageViewPriority(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).priority(Priority.NORMAL).into(mImageView);
} /**
* 策略解说:
* <p>
* all:缓存源资源和转换后的资源
* <p>
* none:不作任何磁盘缓存
* <p>
* source:缓存源资源
* <p>
* result:缓存转换后的资源
*/ //设置缓存策略
public static void loadImageViewDiskCache(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).diskCacheStrategy(DiskCacheStrategy.ALL).into(mImageView);
} /**
* api也提供了几个常用的动画:比如crossFade()
*/ //设置加载动画
public static void loadImageViewAnim(Context mContext, String path, int anim, ImageView mImageView) {
Glide.with(mContext).load(path).animate(anim).into(mImageView);
} /**
* 会先加载缩略图
*/ //设置缩略图支持
public static void loadImageViewThumbnail(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).thumbnail(0.1f).into(mImageView);
} /**
* api提供了比如:centerCrop()、fitCenter()等
*/ //设置动态转换
public static void loadImageViewCrop(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).centerCrop().into(mImageView);
} //设置动态GIF加载方式
public static void loadImageViewDynamicGif(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).asGif().into(mImageView);
} //设置静态GIF加载方式
public static void loadImageViewStaticGif(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).asBitmap().into(mImageView);
} //设置监听的用处 可以用于监控请求发生错误来源,以及图片来源 是内存还是磁盘 //设置监听请求接口
public static void loadImageViewListener(Context mContext, String path, ImageView mImageView, RequestListener<String, GlideDrawable> requstlistener) {
Glide.with(mContext).load(path).listener(requstlistener).into(mImageView);
} //项目中有很多需要先下载图片然后再做一些合成的功能,比如项目中出现的图文混排 //设置要加载的内容
public static void loadImageViewContent(Context mContext, String path, SimpleTarget<GlideDrawable> simpleTarget) {
Glide.with(mContext).load(path).centerCrop().into(simpleTarget);
} //清理磁盘缓存
public static void GuideClearDiskCache(Context mContext) {
//理磁盘缓存 需要在子线程中执行
Glide.get(mContext).clearDiskCache();
} //清理内存缓存
public static void GuideClearMemory(Context mContext) {
//清理内存缓存 可以在UI主线程中进行
Glide.get(mContext).clearMemory();
}
}
图片加载库Glide的封装工具类,方便以后使用的更多相关文章
- Google图片加载库Glide的简单封装GlideUtils
Google图片加载库Glide的简单封装GlideUtils 因为项目里用的Glide的地方比较多,所有简单的封装了以下,其实也没什么,就是写了个工具类,但是还是要把基础说下 Glide的Githu ...
- Android 图片加载库Glide 实战(二),占位符,缓存,转换自签名高级实战
http://blog.csdn.net/sk719887916/article/details/40073747 请尊重原创 : skay <Android 图片加载库Glide 实战(一), ...
- android图片加载库Glide
什么是Glide? Glide是一个加载图片的库,作者是bumptech,它是在泰国举行的google 开发者论坛上google为我们介绍的,这个库被广泛的运用在google的开源项目中. Glide ...
- android 图片加载库 Glide 的使用介绍
一:简介 在泰国举行的谷歌开发者论坛上,谷歌为我们介绍了一个名叫 Glide 的图片加载库,作者是bumptech.这个库被广泛的运用在google的开源项目中,包括2014年google I/O大会 ...
- Google推荐的图片加载库Glide介绍
英文原文 Introduction to Glide, Image Loader Library for Android, recommended by Google 译文首发 http://jco ...
- Google推荐的图片加载库Glide
英文原文 Introduction to Glide, Image Loader Library for Android, recommended by Google 首发地址 http://jco ...
- Aandroid 图片加载库Glide 实战(一),初始,加载进阶到实践
原文: http://blog.csdn.net/sk719887916/article/details/39989293 skay 初识Glide 为何使用 Glide? 有经验的 Android ...
- Android图片加载库的理解
前言 这是“基础自测”系列的第三篇文章,以Android开发需要熟悉的20个技术点为切入点,本篇重点讲讲Android中的ImageLoader这个库的一些理解,在Android上最让人头疼是 ...
- fackbook的Fresco (FaceBook推出的Android图片加载库-Fresco)
[Android开发经验]FaceBook推出的Android图片加载库-Fresco 欢迎关注ndroid-tech-frontier开源项目,定期翻译国外Android优质的技术.开源库.软件 ...
随机推荐
- CSS初窥
- 直接插入排序实现(Java)
直接插入排序介绍 直接插入排序的基本操作是将一个记录插入到已经排好序的有序表中,从而得到一个新的.记录数增1的有序表. 怎么理解呢?就是将n个待排序的元素看成一个有序表和一个无序表,开始时有序 ...
- SQL使用子查询,查找班级成绩最高分
-- 根据要求,获取班级成绩的最高分的学生-- 第一个子查询,先去各个科目的最高,再横向比较各个科目的最高,再取最高分的那个科目-- 第二个子查询,查询每个同学的最高分-- 最后,通过第一个子查询查询 ...
- 机器大数据也离不开Hadoop
转自:http://gtstorageworld.blog.51cto.com/908359/1286758 根据数据来源划分,大数据主要包括三类:商业运作产生的数据.人类行为产生的数据和机器数据.目 ...
- 【Java】认识 JDK,JRE,JVM
JDK,JRE,JVM 今天我们讨论下这三个Java工具 JDK 全称Java Development ToolKit(Java 开发工具包). JDK是整个JAVA的核心,其包括了Java运行环境( ...
- 第5章—构建Spring Web应用程序—关于spring中的validate注解后台校验的解析
关于spring中的validate注解后台校验的解析 在后台开发过程中,对参数的校验成为开发环境不可缺少的一个环节.比如参数不能为null,email那么必须符合email的格式,如果手动进行if判 ...
- ASP.NET 多环境下配置文件web.config的灵活配置---转
注意:本功能在.Net Core中已经不可用,暂时需手动修改web.config中的信息,或者将其设置在appsettings.XXX.json中,然后再使用web.config中的环境变量来制定使用 ...
- 修改ASP.NET文件上传大小限制
转自:http://www.hello-code.com/blog/asp.net/201603/5954.html 要点: 1.web.config中的<httpRuntime maxRequ ...
- 简单Tomcat HTTP RPC框架
RPC基础知识 什么是RPC? RPC(Remote Procedure Call Protocol)——远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议. ...
- nginx 学习笔记(6) nginx配置文件中的度量单位
容量大小可以用比特(byte),千比特(kilobyte,后缀k或者K)或者兆(megabytes,后缀m或者M),例如:“1024”,“8k”,“1m”. 时间间隔可以用毫秒(millisecond ...