图片加载库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优质的技术.开源库.软件 ...
随机推荐
- vmware安装——CentOS-6.5和Mysql
1.新建虚拟机 2.安装centos6.5 3.centos设置 查看网络 4.vmware设置网络连接 关闭selinux [root@china ~]# vim /etc/selinux/conf ...
- 【hdu6058】 Kanade's sum 模拟
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6058 题目大意:给你一个$1$到$n$的排列,请求出该序列所有区间中第$k$大之和,若该区间内少于$ ...
- HUE配置文件hue.ini 的hive和beeswax模块详解(图文详解)(分HA集群和非HA集群)
不多说,直接上干货! 我的集群机器情况是 bigdatamaster(192.168.80.10).bigdataslave1(192.168.80.11)和bigdataslave2(192.168 ...
- js with 语句的用法
with 语句 为语句设定默认对象. with (object) statements 参数 object 新的默认对象. statements 一个或多个语句,object 是该语句的默认对象 ...
- Jav实现F(n)=F(n-1)+F(n-2)+.....+F(1)+1
private static int func(int count) { // TODO Auto-generated method stub int cou = 0; if(count==1) ...
- java 使用 pdf.js 在线查看 pdf 文档
1. 下载对应的 pdf.js 文件: 推荐地址: https://github.com/mozilla/pdf.js/ http://mozilla.g ...
- vs2010查看quartz.net 2.1.2的源码时其中一报错的解决方法
问题: 使用vs2010查看quartz.net 2.1.2的源码时,报错: ..\Quartz.NET-2.1.2\server\Quartz.Server\Quartz.Server.2010.c ...
- 三种数据库访问——原生JDBC
原生的JDBC编程主要分一下几个步骤: (原生的JDBC编程指,仅应用java.sql包下的接口和数据库驱动类编程,而不借助任何框架) 1. 加载JDBC驱动程序: 2. 负责管理JDBC驱动程序的类 ...
- C# 从Excel 批量导入数据库
最近遇到了关于 C# MVC 批量添加数据的问题,解决后就自己写了一个未完成的小Demo 不管什么编程语言都会提供操作Excel文件的方式,C#操作Excel主要有以下几种方式: 1.Excel 说 ...
- .net WINFORM的GDI双缓冲的实现
有时候在窗体中执行不断的GDI+操作的时候会出现闪速的状况,除了修改窗体的参数,更应该解决刷新本身的问题,双缓冲可能就是这样来的. 方法1: 用GDI绘制在位图上,然后再重新生成位图 Bitmap b ...