图片加载库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优质的技术.开源库.软件 ...
随机推荐
- Codeforces Round #555 (Div. 3) c2 d e f
c2:Increasing Subsequence (hard version) 那边小取那边,然后相等比较后面的长度 #include<bits/stdc++.h> using name ...
- 马哥Python 开发9期
LVS工作模式: 传输层 会话保持:负载均衡(1) session sticky:同一用户调度固定服务器Source IP:LVS sh算法(对某一特定服务而言)Cookie(2) session r ...
- Ubuntu14.04安装之后的一些配置
不多说,直接上干货! 主要分为 一.root用户的开启和vim编辑器的安装 二.ssh的安装 三.静态ip的设置 四.中英切换文环境切换 一.root用户的开启和vim编辑器的安装 Ubuntu在默认 ...
- golang---interface结合reflect的泛型应用
大致思路:序列化未知json放入一个interface{}中再通过反射将其内容解析出来 str1:=`{ , , , , , , "type_key": "testnow ...
- dephi(pascal)中修改Label字体的样式(加粗,斜体,下划线)
不废话,直接代码: Label1.Font.style:=[fsBold,fsItalic,fsUnderline]; //加粗.斜体,下划线
- ZooKeeper:架构和算法
ZooKeeper主要用来解决分布式应用场景中存在的一些问题,如:统一命名服务.状态同步服务.集群管理.分布式应用配置管理等. 它支持Standalone模式和分布式模式,在分布式模式下,能够为分布式 ...
- 在Java Web项目中,不用ActionContext类来获得tomcat部署项目的绝对路径
例子:sendIosApns.class.getClassLoader().getResource("").getFile().replaceAll("%20" ...
- Druid连接池(四)
十七.Druid加密 运维和DBA都不希望把密码明文直接写在配置文件中,Druid提供了数据库密码加密的功能. ConfigFilter的作用包括: 从配置文件中读取配置 从远程http文件中读取配置 ...
- 细说setTimeout/setImmediate/process.nextTick的区别
node.js中的非IO的异步API提供了四种方法,分别为setTimeOut(),setInterval(),setImmediate()以及process.nextTick(),四种方法实现原理相 ...
- CSS Sprite 精灵图
.bg_sprite{background-image:url(/整图地址); background-repeat:no-repeat} 引用该类 .. 然后在元素中逐一定义背景坐标 .. 以下为关键 ...