NetworkImageView 分析:public class NetworkImageView extends ImageView 他继承自ImageView,并且添加了一个新方法: public void setImageUrl(String url, ImageLoader imageLoader) {}该参数包含一个Url地址和一个ImageLoader对象

还有一个核心方法

private void loadImageIfNecessary(final boolean isInLayoutPass) {}

内部实现,boolean 类型参数代表是否重新请求网络 ,true:重新请求 false:取缓存

内部实现和 ImageLoader类似,都是通过ImageContainer中new一个ImageListener,在ImageListener,只是做了 Url的空判断,如果Url为null,则调用ImageContainer.cancelRequest();取消请求
 
同时覆盖以下几个方法
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
//onLayout时重新请求
loadImageIfNecessary(true);
}
@Override
protected void onDetachedFromWindow() {
//销毁View的时候Release操作
if (mImageContainer != null) {
// If the view was bound to an image request, cancel it and clear
// out the image from the view.
mImageContainer.cancelRequest();
setImageBitmap(null);
// also clear out the container so we can reload the image if necessary.
mImageContainer = null;
}
super.onDetachedFromWindow();
}
//drawable状态改变重绘
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
invalidate();
}

总结:网络请求下载图片显示,可以使用此控件,比传统的ImageView多了网络处理,也添加了2个方法,设置开始下载的默认图和下载出错后显示图

/**
* Sets the default image resource ID to be used for this view until the attempt to load it
* completes.
*/
public void setDefaultImageResId(int defaultImage) {
mDefaultImageId = defaultImage;
} /**
* Sets the error image resource ID to be used for this view in the event that the image
* requested fails to load.
*/
public void setErrorImageResId(int errorImage) {
mErrorImageId = errorImage;
}

Android 网络通信框架Volley(三)的更多相关文章

  1. Android 网络通信框架Volley简介(Google IO 2013)

    1. 什么是Volley 在这之前,我们在程序中需要和网络通信的时候,大体使用的东西莫过于AsyncTaskLoader,HttpURLConnection,AsyncTask,HTTPClient( ...

  2. [转]Android 网络通信框架Volley简介(Google IO 2013)

    Volley主页 https://android.googlesource.com/platform/frameworks/volley http://www.youtube.com/watch?v= ...

  3. 【转】Android 网络通信框架Volley简介(Google IO 2013)

    Volley主页 https://android.googlesource.com/platform/frameworks/volley http://www.youtube.com/watch?v= ...

  4. Android 网络通信框架Volley(一)

    转自:http://blog.csdn.net/t12x3456/article/details/9221611 1. 什么是Volley 在这之前,我们在程序中需要和网络通信的时候,大体使用的东西莫 ...

  5. Android 网络通信框架Volley简介

    1.1. Volley引入的背景在以前,我们可能面临如下很多麻烦的问题. 比如以前从网上下载图片的步骤可能是这样的流程: 在ListAdapter#getView()里开始图像的读取. 通过Async ...

  6. Android 网络通信框架Volley基本介绍

    Volley主页 https://android.googlesource.com/platform/frameworks/volley http://www.youtube.com/watch?v= ...

  7. Android 网络通信框架Volley的简单使用

    Volley是Android平台上的网络通信库,能使网络通信更快,更简单,更健壮. Volley提供的功能: JSON,图像等的异步下载: 网络请求的排序(scheduling) 网络请求的优先级处理 ...

  8. Android 网络通信框架Volley(二)

    Volley提供2个静态方法: public static RequestQueue newRequestQueue(Context context) {} public static Request ...

  9. Android网络框架Volley(体验篇)

    Volley是Google I/O 2013推出的网络通信库,在volley推出之前我们一般会选择比较成熟的第三方网络通信库,如: android-async-http retrofit okhttp ...

随机推荐

  1. js网页倒计时功能(天,时,分,秒)

    给定任何一个时间,然后实现现在到那个时间的倒计时. 下面的例子是显示现在到2019年8月1号0时0分的倒计时: <div class="list"> <span ...

  2. c语言实现基本的数据结构(六) 串

    #include <stdio.h> #include <tchar.h> #include <stdlib.h> // TODO: 在此处引用程序需要的其他头文件 ...

  3. Executor线程池只看这一篇就够了

    线程池为线程生命周期的开销和资源不足问题提供了解决方 案.通过对多个任务重用线程,线程创建的开销被分摊到了多个任务上. 线程实现方式 Thread.Runnable.Callable //实现Runn ...

  4. net core Webapi基础工程搭建(六)——数据库操作_Part 2

    目录 前言 开始 使用 小结 前言 昨天是写着写着发现,时间不早了,已经养成了晚上下班抽时间看看能写点儿啥的习惯(貌似),今天实在是不想让昨天没做完的事情影响,所以又坐下,沉下心(周末了),开始把数据 ...

  5. springboot + jedisCluster

    如果使用的是redis2.x,在项目中使用客户端分片(Shard)机制. 如果使用的是redis3.x中的集群,在项目中使用jedisCluster. 1.项目结构 2.pom.xml 1 <? ...

  6. 【持续集成】GitLab CI + Docker 实现持续集成

    GitLab CI + Docker 实现持续集成 一.持续集成(Continuous Integration, CI)的基本概念 概述 在传统软件的开发中,代码的集成工作通常是在所有人都将工作完成后 ...

  7. Windows内核原理-同步IO与异步IO

    目录 Windows内核原理-同步IO与异步IO 背景 目的 I/O 同步I/O 异步I/O I/O完成通知 总结 参考文档 Windows内核原理-同步IO与异步IO 背景 在前段时间检查异常连接导 ...

  8. elk安装与搭建

    Elasticsearch安装配置 ·下载elasticsearch.tar.gz包,解压压缩包.(此处为单机版es,集群请参考 https://www.cnblogs.com/lazycxy/p/9 ...

  9. jsDeliver+github使用教程,免费的cdn

    欢迎访问我的个人博客皮皮猪:http://www.zhsh666.xyz 前言:CDN的全称是Content Delivery Network,即内容分发网络.CDN是构建在网络之上的内容分发网络,依 ...

  10. Fire Balls 04——砖塔的创建,动态上升以及旋转

    版权申明: 本文原创首发于以下网站: 博客园『优梦创客』的空间:https://www.cnblogs.com/raymondking123 优梦创客的官方博客:https://91make.top ...