在安卓开发过程中难免会遇到下面几个情况:

1、图片异步载入

2、图片缓存

3、图片显示

4、其他……(忘记了)

以上的这些情况,可能要自己去写不少代码去实现这些功能。并且对于一些新手,可能写了半天,发现效果非常不理想、内存问题也处理不好、异步也不好控制(我就是这样)。所以搜了一下。发现网上最流行的一个安卓图片开源框架 universal-image-loader,亲自使用了一下,发现真是的好用啊。一共就加十几行代码就搞定了。妈妈再也不用操心我花时间去瞎搞八搞的了!

好了。以下来说说高速使用这个框架的步骤:

一、往project的libs目录中加入 universal-image-loader-1.9.2-with-sources.jar 这个Jar包。

点击这里能够直接下载哦!

二、新建一个 继承application的类。当中的代码看以下:

public class MyApplication extends Application {
public void onCreate() {
super.onCreate();
initImageLoader(getApplicationContext());
} public static void initImageLoader(Context context) {
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.threadPriority(Thread.MAX_PRIORITY).denyCacheImageMultipleSizesInMemory()
.diskCacheFileNameGenerator(new Md5FileNameGenerator()).tasksProcessingOrder(QueueProcessingType.LIFO)
.writeDebugLogs() // Remove for release app
.build();
ImageLoader.getInstance().init(config);
} }

注意。这个application类要在menifest中的application标签中注明哦。就是以下这样:

<application

android:name="com.lee.example.MyApplication"

好了,加入完以上两步的内容,主要的框架环境就搭建好了。以下是怎样使用它来载入网络图片:

先声明两个对象:

private DisplayImageOptions
options;

private ImageLoader
imageLoader;

然后在类的构造函数或者activity的increate方法中初始化它们:

imageLoader = ImageLoader.getInstance();

options =
new DisplayImageOptions.Builder()

.showImageOnLoading(null)//载入过程中显示的图片

.showImageForEmptyUri(null)//载入内容为空显示的图片

.showImageOnFail(null)//载入失败显示的图片

.cacheInMemory(true).cacheOnDisk(true).considerExifParams(true)

.bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(388)).build();

以下是使用:

imageLoader.displayImage(imageFile,
imageView, options);

说明:

imageFile:图片的网络路径(也能够用本地的路径哦,详情看文末的框架github中文档说明)

imageView:就是图片控件哈~

就上面这么一句。太方便了哈。

框架的github地址:https://github.com/nostra13/Android-Universal-Image-Loader

小广告:关注微信公众号:“大大花猫” ,它是一个智能聊天机器人,能够回答各种问题,包含查询各种信息哦!

它还能够进行人脸识别,仅仅要发送一张人脸照片,就能够进行识别并回复出各种信息哦!

它还有很多微信网页小游戏哦!还有很多其它精彩功能正在开发中! 快快关注吧!^ ^

安卓图片框架:universal-image-loader的高速使用的更多相关文章

  1. Android 使用图片异步载入框架Universal Image Loader的问题

    使用的Jar包 问题:        optionsm = new DisplayImageOptions.Builder()         .displayer(new RoundedBitmap ...

  2. Android中Universal Image Loader开源框架的简单使用

    UIL (Universal Image Loader)aims to provide a powerful, flexible and highly customizable instrument ...

  3. universal image loader在listview/gridview中滚动时重复加载图片的问题及解决方法

    在listview/gridview中使用UIL来display每个item的图片,当图片数量较多需要滑动滚动时会出现卡顿,而且加载过的图片再次上翻后依然会重复加载(显示设置好的加载中图片) 最近在使 ...

  4. Fresco图片框架内部实现原理探索

    流行的网络框架 目前流行的网络图片框架: Picasso.Universal Image Loader.Volley的(ImageLoader.NetworkImageView).Glide和Fres ...

  5. 开源项目Universal Image Loader for Android 说明文档 (1) 简单介绍

     When developing applications for Android, one often facesthe problem of displaying some graphical ...

  6. universal image loader自己使用的一些感受

    1.全局入口的Application定义初始化: ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Build ...

  7. 【译】UNIVERSAL IMAGE LOADER. PART 3---ImageLoader详解

    在之前的文章,我们重点讲了Android-Universal-Image-Loader的三个主要组件,现在我们终于可以开始使用它了. Android-Universal-Image-Loader有四个 ...

  8. 【Android应用开发】 Universal Image Loader ( 使用简介 | 示例代码解析 )

    作者 : 韩曙亮 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/50824912 相关地址介绍 : -- Universal I ...

  9. android universal image loader 缓冲原理详解

    1. 功能介绍 1.1 Android Universal Image Loader Android Universal Image Loader 是一个强大的.可高度定制的图片缓存,本文简称为UIL ...

随机推荐

  1. linux系统怎么改为中文版(转)

    linux系统安装好后怎么改为中文版呢?今天就跟大家介绍下linux系统改为中文版的方法,希望能帮助到大家! 以下是linux系统改为中文版的四种方法,一起来看看: 方法1:写入环境变量 echo & ...

  2. sriov查看pf-vf对应关系

    自己写的, 方便调试. $ cat pf-vf echo "physfn is $1"echo "pf info:"ls /sys/class/net/$1 - ...

  3. hdu 1690 The Balance_母函数

    题意:给你n个数,这些数可以互相加或者减,输出在范围[1,sum]里不能通过运算得出的数 思路:套母函数模版 #include <iostream> #include<cstdio& ...

  4. C app

    1,C 输入输出字符串

  5. bat命令学习笔记

    1.一般在开始声明 setlocal enabledelayedexpansion 设置本地为延迟扩展.其实也就是:延迟变量,全称延迟环境变量扩展,使得批处理能够感知到变量的动态变化,在运行过程中给变 ...

  6. KMP算法java实现

    /** * 假设现在文本串S匹配到 i 位置,模式串P匹配到 j 位置 如果j = -1,或者当前字符匹配成功(即S[i] == * P[j]),都令i++,j++,继续匹配下一个字符: 如果j != ...

  7. 升级Xcode7后所要更改的配置

    http://blog.csdn.net/huxiaoqiao163/article/details/48711077

  8. Linux fdisk命令参数及用法详解---Linux磁盘分区管理命令fdisk

    fdisk 命令 linux磁盘分区管理 用途:观察硬盘之实体使用情形与分割硬盘用. 使用方法: 一.在 console 上输入 fdisk -l /dev/sda ,观察硬盘之实体使用情形. 二.在 ...

  9. 1033. To Fill or Not to Fill (25)

     题目链接:http://www.patest.cn/contests/pat-a-practise/1033 题目: 1033. To Fill or Not to Fill (25) 时间限制 1 ...

  10. android典型监听事件实

    public class MainActivity extends Activity { int counter; Button add, sub; TextView display; @Overri ...