大神原网址: http://blog.csdn.net/lmj623565791/article/details/41874561 

思路:

1. 压缩图片

压缩本地图片: 获得imageview想要显示的大小 -> 设置合适的inSampleSize

    压缩网络图片:

a. 硬盘缓存开启 -> 直接下载存到sd卡,然后采用本地的压缩方案

b. 硬盘缓存关闭 -> 使用BitmapFactory.decodeStream(is, null, opts);

2. 图片加载架构

图片压缩加载完 -> 放入LruCache -> 设置到ImageView上

1、单例,包含一个LruCache用于管理我们的图片;
        2、任务队列,我们每来一次加载图片的请求,我们会封装成Task存入我们的TaskQueue;
        3、包含一个后台线程,这个线程在第一次初始化实例的时候启动,然后会一直在后台运行;
                    任务呢?还记得我们有个任务队列么,有队列存任务,得有人干活呀;
                    所以,当每来一次加载图片请求的时候,我们同时发一个消息到后台线程,后台线程去使用线程池去TaskQueue去取一个任务执行;
        4、调度策略;3中说了,后台线程去TaskQueue去取一个任务,这个任务不是随便取的,有策略可以选择,一个是FIFO(先进先出),一个是LIFO(后进先出),我倾向于后者。

代码简析:

三个主要文件:

  1. ImageSizeUtil.java
  1. package com.carloz.diy.imageloader;
  2.  
  3. import android.graphics.BitmapFactory;
  4. import android.util.DisplayMetrics;
  5. import android.view.ViewGroup;
  6. import android.widget.ImageView;
  7.  
  8. /**
  9. * Created by root on 15-11-13.
  10. */
  11. public class ImageSizeUtil {
  12.  
  13. public static class ImageSize {
  14. int width;
  15. int height;
  16. }
  17.  
  18. /**
  19. * 获得imageview想要显示的大小
  20. *
  21. * 可以看到,我们拿到imageview以后:
  22. * 首先企图通过getWidth获取显示的宽;有些时候,这个getWidth返回的是0;
  23. * 那么我们再去看看它有没有在布局文件中书写宽;
  24. * 如果布局文件中也没有精确值,那么我们再去看看它有没有设置最大值;
  25. * 如果最大值也没设置,那么我们只有拿出我们的终极方案,使用我们的屏幕宽度;
  26. * 总之,不能让它任性,我们一定要拿到一个合适的显示值。
  27. * 可以看到这里或者最大宽度,我们用的反射,而不是getMaxWidth();
  28. * 维萨呢,因为getMaxWidth竟然要API 16,我也是醉了;为了兼容性,我们采用反射的方案。反射的代码就不贴了。
  29. * @param imageView
  30. * @return imageView的大小
  31. */
  32. public static ImageSize getImageViewSize(ImageView imageView) {
  33. ImageSize imageSize = new ImageSize();
  34. DisplayMetrics displayMetrics = imageView.getContext().getResources().getDisplayMetrics();
  35.  
  36. ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
  37. int width = imageView.getWidth();
  38. if(width <= 0) width = layoutParams.width;
  39. // if(width <= 0) width = imageView.getMaxWidth();
  40. if(width <= 0) width = displayMetrics.widthPixels;
  41.  
  42. int height = imageView.getHeight();
  43. if(height <= 0) height = layoutParams.height;
  44. // if(height <= 0) height = imageView.getMaxHeight();
  45. if(height <= 0) height = displayMetrics.heightPixels;
  46.  
  47. imageSize.width = width;
  48. imageSize.height = height;
  49. return imageSize;
  50. }
  51.  
  52. /**
  53. * 计算BitmapFactory.Options options 中的 inSampleSize, 加载图片的大小的重要参数
  54. * 根据需求的宽和高以及图片实际的宽和高计算inSampleSize
  55. * 1. 如果 inSampleSize > 1,返回一个较小的图像保存在内存中.
  56. * 例如,insamplesize = = 4返回一个图像是1 / 4的宽度/高度的图像
  57. * 2. 如果 inSampleSize <= 1, 返回原始图像
  58. * @param options 保存着实际图片的大小
  59. * @param reqWidth 压缩后图片的 width
  60. * @param reqHeight 压缩后图片的 height
  61. * @return options里面存了实际的宽和高;reqWidth和reqHeight就是我们之前得到的想要显示的大小;
  62. * 经过比较,得到一个合适的inSampleSize;
  63. */
  64. public static int caculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
  65. int inSampleSize = 1;
  66. int width = options.outWidth, height=options.outHeight;
  67.  
  68. if(width > reqWidth || height > reqHeight) {
  69. int widthRadio = Math.round(width/reqWidth);
  70. int heightRadio = Math.round(height/reqHeight);
  71. inSampleSize = Math.max(widthRadio, heightRadio);
  72. }
  73.  
  74. return inSampleSize;
  75. }
  76.  
  77. }
  1. DownloadImgUtils.java
  1. package com.carloz.diy.imageloader;
  2.  
  3. import android.graphics.Bitmap;
  4. import android.graphics.BitmapFactory;
  5. import android.widget.ImageView;
  6.  
  7. import java.io.BufferedInputStream;
  8. import java.io.File;
  9. import java.io.FileOutputStream;
  10. import java.io.IOException;
  11. import java.io.InputStream;
  12. import java.net.HttpURLConnection;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15.  
  16. /**
  17. * Created by root on 15-11-16.
  18. */
  19. public class DownloadImgUtils {
  20.  
  21. public static Bitmap downloadImageByUrl(String imgUrl, ImageView imageView) {
  22.  
  23. if (null == imgUrl) return null;
  24. try {
  25. URL url = new URL(imgUrl);
  26. HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
  27. InputStream is = new BufferedInputStream(httpConn.getInputStream());
  28. is.mark(is.available()); // 在InputStream中设置一个标记位置.
  29. // 参数readlimit 表示多少字节可以读取.
  30. // 调用reset()将重新流回到标记的位置
  31. BitmapFactory.Options options = new BitmapFactory.Options();
  32. options.inJustDecodeBounds = true;
  33. BitmapFactory.decodeStream(is, null, options);
  34. // 获取imageview想要显示的宽和高
  35. ImageSizeUtil.ImageSize imageSize = ImageSizeUtil.getImageViewSize(imageView);
  36. options.inSampleSize = ImageSizeUtil.caculateInSampleSize(options, imageSize.width, imageSize.height);
  37. options.inJustDecodeBounds = false;
  38. is.reset(); // Resets this stream to the last marked location.
  39. Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
  40. httpConn.disconnect();
  41. is.close();
  42. return bitmap;
  43. } catch (MalformedURLException e) {
  44. e.printStackTrace();
  45. } catch (IOException e) {
  46. e.printStackTrace();
  47. }
  48. return null;
  49. }
  50.  
  51. /**
  52. * 根据url下载图片在指定的文件
  53. * @param urlStr
  54. * @param file
  55. * @return
  56. */
  57. public static boolean downloadImageByUrl(String urlStr, File file) {
  58. FileOutputStream fos = null;
  59. InputStream is = null;
  60. try {
  61. URL url = new URL(urlStr);
  62. HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  63.  
  64. is = conn.getInputStream();
  65. fos = new FileOutputStream(file);
  66. byte[] buf = new byte[512];
  67. int len = 0;
  68. while ((len = is.read(buf)) != -1) {
  69. fos.write(buf, 0, len);
  70. }
  71. fos.flush();
  72. return true;
  73.  
  74. } catch (Exception e) {
  75. e.printStackTrace();
  76. } finally {
  77. try {
  78. if (is != null)
  79. is.close();
  80. } catch (IOException e) {
  81. }
  82.  
  83. try {
  84. if (fos != null)
  85. fos.close();
  86. } catch (IOException e) {
  87. e.printStackTrace();
  88. }
  89. }
  90. return false;
  91. }
  92.  
  93. }
  1. MyImageLoader.java
  1. package com.carloz.diy.imageloader;
  2.  
  3. import android.content.Context;
  4. import android.graphics.Bitmap;
  5. import android.graphics.BitmapFactory;
  6. import android.os.Environment;
  7. import android.os.Handler;
  8. import android.os.Looper;
  9. import android.os.Message;
  10. import android.util.Log;
  11. import android.util.LruCache;
  12. import android.widget.ImageView;
  13.  
  14. import java.io.File;
  15. import java.security.MessageDigest;
  16. import java.security.NoSuchAlgorithmException;
  17. import java.util.LinkedList;
  18. import java.util.concurrent.ExecutorService;
  19. import java.util.concurrent.Executors;
  20. import java.util.concurrent.Semaphore;
  21.  
  22. /**
  23. * Created by root on 15-11-13.
  24. */
  25. public class MyImageLoader {
  26.  
  27. public static final String TAG = "MyImageLoader";
  28.  
  29. private static MyImageLoader mInstance;
  30. private LruCache<String, Bitmap> mLruCache; // 图片缓存的核心对象
  31. private ExecutorService mThreadPool; // 线程池
  32. private static final int DEFAULT_THREAD_COUNT = 1;
  33.  
  34. private LinkedList<Runnable> mTaskQueue; // 任务队列
  35.  
  36. private Thread mBackstageThread; // 后台轮询线程
  37. private Handler mBackstageThreadHandler;
  38.  
  39. // Semaphore, 它负责协调各个线程, 以保证它们能够正确、合理的使用公共资源。
  40. // 也是操作系统中用于控制进程同步互斥的量。
  41. // Semaphore分为单值和多值两种,前者只能被一个线程获得,后者可以被若干个线程获得。
  42. // 停车场系统中,车位是公共资源,每辆车好比一个线程,看门人起的就是信号量的作用
  43. private Semaphore mBackstageThreadSemaphore;
  44. private Semaphore mBackstageThreadHandlerSemaphore = new Semaphore(0);
  45.  
  46. private static final Object syncObject = new Object(); // 单例模式 && synchronized
  47.  
  48. public enum QueueType {FIFO, LIFO}
  49.  
  50. private QueueType mType = QueueType.LIFO;
  51.  
  52. private boolean isDiskCacheEnable = true; // 硬盘缓存可用
  53.  
  54. // UI Thread
  55. private Handler mUIHandler;
  56.  
  57. /**
  58. * 单例模式
  59. *
  60. * @param threadCount
  61. * @return
  62. */
  63. public static MyImageLoader getInstance(int threadCount, QueueType type) {
  64. if (mInstance == null) {
  65. synchronized (syncObject) {
  66. if (mInstance == null) {
  67. mInstance = new MyImageLoader(threadCount, type);
  68. }
  69. }
  70. }
  71. return mInstance;
  72. }
  73.  
  74. public static MyImageLoader getInstance() {
  75. if (mInstance == null) {
  76. synchronized (syncObject) {
  77. if (mInstance == null) {
  78. mInstance = new MyImageLoader(DEFAULT_THREAD_COUNT, QueueType.LIFO);
  79. }
  80. }
  81. }
  82. return mInstance;
  83. }
  84.  
  85. private MyImageLoader(int threadCount, QueueType type) {
  86. init(threadCount, type);
  87. }
  88.  
  89. private void init(int threadCount, QueueType type) {
  90. initBackThread();
  91.  
  92. // get the max available memory
  93. int maxMemory = (int) Runtime.getRuntime().maxMemory();
  94. int cacheMemory = maxMemory / 8;
  95.  
  96. // 继承LruCache时,必须要复写sizeof方法,用于计算每个条目的大小
  97. // the size of bitmap can not over cacheMemory
  98. mLruCache = new LruCache<String, Bitmap>(cacheMemory) {
  99. @Override
  100. protected int sizeOf(String key, Bitmap value) {
  101. return value.getByteCount();
  102. }
  103. };
  104.  
  105. // create thread pool that
  106. // reuses a fixed number of threads operating off a shared unbounded queue.
  107. mThreadPool = Executors.newFixedThreadPool(threadCount);
  108. mTaskQueue = new LinkedList<>();
  109. mType = type;
  110. mBackstageThreadSemaphore = new Semaphore(threadCount);
  111. }
  112.  
  113. /**
  114. * 初始化后台轮询线程
  115. */
  116. private void initBackThread() {
  117. mBackstageThread = new Thread() {
  118. @Override
  119. public void run() {
  120. Looper.prepare();
  121. mBackstageThreadHandler = new Handler() {
  122. @Override
  123. public void handleMessage(Message msg) {
  124. mThreadPool.execute(getTask()); // 线程池去取出一个任务进行执行
  125. try {
  126. mBackstageThreadSemaphore.acquire();
  127. } catch (InterruptedException e) {
  128. e.printStackTrace();
  129. }
  130. }
  131. };
  132. mBackstageThreadHandlerSemaphore.release(); // 释放一个信号量
  133. Looper.loop();
  134. }
  135. };
  136. mBackstageThread.start();
  137. }
  138.  
  139. public void loadImage(String path, final ImageView imageView, boolean isFromNet) {
  140. imageView.setTag(path);
  141. if (mUIHandler == null) {
  142. mUIHandler = new Handler() {
  143. @Override
  144. public void handleMessage(Message msg) {
  145. ImageBeanHolder holder = (ImageBeanHolder) msg.obj;
  146. Bitmap bm = holder.bitmap;
  147. ImageView iv = holder.imageView;
  148. String path2 = holder.path;
  149. if (iv.getTag().toString().equals(path2)) {
  150. iv.setImageBitmap(bm);
  151. }
  152. }
  153. };
  154. }
  155.  
  156. Bitmap bitmap = getBitmapFromLruCache(path); // 根据path在缓存中获取bitmap
  157. if (bitmap != null) {
  158. refreshBitmap(path, imageView, bitmap);
  159. } else {
  160. addTask(buildTask(path, imageView, isFromNet));
  161. }
  162. }
  163.  
  164. private void refreshBitmap(String path, final ImageView imageView, Bitmap bitmap) {
  165. Message msg = Message.obtain();
  166. ImageBeanHolder holder = new ImageBeanHolder();
  167. holder.bitmap = bitmap;
  168. holder.path = path;
  169. holder.imageView = imageView;
  170. msg.obj = holder;
  171. mUIHandler.sendMessage(msg);
  172. }
  173.  
  174. /**
  175. * 就是runnable加入TaskQueue,与此同时使用mBackstageThreadHandler(这个handler还记得么,
  176. * 用于和我们后台线程交互。)去发送一个消息给后台线程,叫它去取出一个任务执行
  177. *
  178. * @param runnable
  179. */
  180. private synchronized void addTask(Runnable runnable) {
  181. mTaskQueue.add(runnable);
  182. try {
  183. if (mBackstageThreadHandler == null)
  184. mBackstageThreadHandlerSemaphore.acquire();
  185. } catch (InterruptedException e) {
  186. e.printStackTrace();
  187. }
  188. mBackstageThreadHandler.sendEmptyMessage(0x110); //
  189. }
  190.  
  191. /**
  192. * 就是根据Type从任务队列头或者尾进行取任务
  193. *
  194. * @return
  195. */
  196. private Runnable getTask() {
  197. if (mType == QueueType.FIFO) {
  198. return mTaskQueue.removeFirst();
  199. } else if (mType == QueueType.LIFO) {
  200. return mTaskQueue.removeLast();
  201. }
  202. return null;
  203. }
  204.  
  205. /**
  206. * 我们新建任务,说明在内存中没有找到缓存的bitmap;我们的任务就是去根据path加载压缩后的bitmap返回即可,然后加入LruCache,设置回调显示。
  207. * 首先我们判断是否是网络任务?
  208. * 如果是,首先去硬盘缓存中找一下,(硬盘中文件名为:根据path生成的md5为名称)。
  209. * 如果硬盘缓存中没有,那么去判断是否开启了硬盘缓存:
  210. * 开启了的话:下载图片,使用loadImageFromLocal本地加载图片的方式进行加载(压缩的代码前面已经详细说过);
  211. * 如果没有开启:则直接从网络获取(压缩获取的代码,前面详细说过);
  212. * 如果不是网络图片:直接loadImageFromLocal本地加载图片的方式进行加载
  213. * 经过上面,就获得了bitmap;然后加入addBitmapToLruCache,refreashBitmap回调显示图片
  214. *
  215. * @param path
  216. * @param imageView
  217. * @param isFromNet
  218. * @return
  219. */
  220. private Runnable buildTask(final String path, final ImageView imageView, final boolean isFromNet) {
  221. return new Runnable() {
  222. @Override
  223. public void run() {
  224. Bitmap bitmap = null;
  225. if (isFromNet) {
  226. File file = getDiskCacheDir(imageView.getContext(), md5(path));
  227. if (file.exists()) { // 如果本地已经缓存了该文件
  228. bitmap = loadImageFromLocal(file.getAbsolutePath(), imageView);
  229. if (bitmap == null)
  230. Log.d(TAG, "load image failed from local: " + path);
  231. } else { // 需要从网络下载
  232. if (isDiskCacheEnable) { // 检测是否开启硬盘缓存
  233. boolean downloadState = DownloadImgUtils.downloadImageByUrl(path, file);
  234. if (downloadState) {
  235. bitmap = loadImageFromLocal(file.getAbsolutePath(), imageView);
  236. }
  237. if (bitmap == null)
  238. Log.d(TAG, "download image failed to diskcache(" + path + ")");
  239. } else { // 直接从网络加载到imageView
  240. bitmap = DownloadImgUtils.downloadImageByUrl(path, imageView);
  241. if (bitmap == null)
  242. Log.d(TAG, "download image failed to memory(" + path + ")");
  243. }
  244. }
  245. } else {
  246. bitmap = loadImageFromLocal(path, imageView);
  247. }
  248. addBitmapToLruCache(path, bitmap);
  249. refreshBitmap(path, imageView, bitmap);
  250. mBackstageThreadSemaphore.release();
  251. }
  252. };
  253. }
  254.  
  255. /**
  256. * 使用loadImageFromLocal本地加载图片的方式进行加载
  257. *
  258. * @param path
  259. * @param imageView
  260. * @return
  261. */
  262. private Bitmap loadImageFromLocal(final String path, final ImageView imageView) {
  263. Bitmap bitmap = null;
  264. // 1、获得图片需要显示的大小
  265. ImageSizeUtil.ImageSize imageSize = ImageSizeUtil.getImageViewSize(imageView);
  266. // 2、压缩图片
  267. bitmap = decodeSampledBitmapFromPath(path, imageSize.width, imageSize.height);
  268. return bitmap;
  269. }
  270.  
  271. /**
  272. * 将图片加入LruCache
  273. *
  274. * @param path
  275. * @param bitmap
  276. */
  277. protected void addBitmapToLruCache(String path, Bitmap bitmap) {
  278. if (getBitmapFromLruCache(path) == null) {
  279. if (bitmap != null)
  280. mLruCache.put(path, bitmap);
  281. }
  282. }
  283.  
  284. /**
  285. * 根据图片需要显示的宽和高对图片进行压缩
  286. *
  287. * @param path
  288. * @param width
  289. * @param height
  290. * @return
  291. */
  292. protected Bitmap decodeSampledBitmapFromPath(String path, int width, int height) {
  293. // 获得图片的宽和高,并不把图片加载到内存中
  294. BitmapFactory.Options options = new BitmapFactory.Options();
  295. options.inJustDecodeBounds = true;
  296. BitmapFactory.decodeFile(path, options);
  297.  
  298. options.inSampleSize = ImageSizeUtil.caculateInSampleSize(options, width, height);
  299. // 使用获得到的InSampleSize再次解析图片
  300. options.inJustDecodeBounds = false;
  301. Bitmap bitmap = BitmapFactory.decodeFile(path, options);
  302.  
  303. if (null == bitmap)
  304. Log.d(TAG, "options.inSampleSize = " + options.inSampleSize + ", " + path);
  305. return bitmap;
  306. }
  307.  
  308. /**
  309. * 获得缓存图片的地址
  310. *
  311. * @param context
  312. * @param uniqueName
  313. * @return
  314. */
  315. public File getDiskCacheDir(Context context, String uniqueName) {
  316. String cachePath;
  317. if (false && Environment.MEDIA_MOUNTED.equals(Environment
  318. .getExternalStorageState())) {
  319. cachePath = context.getExternalCacheDir().getPath();
  320. } else {
  321. cachePath = context.getCacheDir().getPath();
  322. }
  323. return new File(cachePath + File.separator + uniqueName);
  324. }
  325.  
  326. /**
  327. * 根据path在缓存中获取bitmap
  328. *
  329. * @param key
  330. * @return
  331. */
  332. private Bitmap getBitmapFromLruCache(String key) {
  333. return mLruCache.get(key);
  334. }
  335.  
  336. /**
  337. * 利用签名辅助类,将字符串字节数组
  338. *
  339. * @param str
  340. * @return
  341. */
  342. public String md5(String str) {
  343. byte[] digest = null;
  344. try {
  345. MessageDigest md = MessageDigest.getInstance("md5");
  346. digest = md.digest(str.getBytes());
  347. return bytes2hex02(digest);
  348.  
  349. } catch (NoSuchAlgorithmException e) {
  350. e.printStackTrace();
  351. }
  352. return null;
  353. }
  354.  
  355. /**
  356. * 方式二
  357. *
  358. * @param bytes
  359. * @return
  360. */
  361. public String bytes2hex02(byte[] bytes) {
  362. StringBuilder sb = new StringBuilder();
  363. String tmp = null;
  364. for (byte b : bytes) {
  365. // 将每个字节与0xFF进行与运算,然后转化为10进制,然后借助于Integer再转化为16进制
  366. tmp = Integer.toHexString(0xFF & b);
  367. if (tmp.length() == 1)// 每个字节8为,转为16进制标志,2个16进制位
  368. {
  369. tmp = "0" + tmp;
  370. }
  371. sb.append(tmp);
  372. }
  373.  
  374. return sb.toString();
  375.  
  376. }
  377.  
  378. private class ImageBeanHolder {
  379. Bitmap bitmap;
  380. ImageView imageView;
  381. String path;
  382. }
  383. }

以上就是整个框架

使用方法:   mImageLoader.loadImage(path, iv_popup, true);

在 4.0 的屏幕上不能录制屏幕... 好伤心, 以后再补

Android自定义图片加载框架的更多相关文章

  1. Android之图片加载框架Fresco基本使用(一)

    PS:Fresco这个框架出的有一阵子了,也是现在非常火的一款图片加载框架.听说内部实现的挺牛逼的,虽然自己还没研究原理.不过先学了一下基本的功能,感受了一下这个框架的强大之处.本篇只说一下在xml中 ...

  2. android Glide图片加载框架的初探

    一.Glide图片加载框架的简介 谷歌2014年开发者论坛会上介绍的图片加载框架,它让我们在处理不管是网路下载的图片还是本地的图片,减轻了很多工作量, 二.开发步骤: 1.添加链接库 compile ...

  3. android glide图片加载框架

    项目地址: https://github.com/bumptech/glide Glide作为安卓开发常用的图片加载库,有许多实用而且强大的功能,那么,今天就来总结一番,这次把比较常见的都写出来,但并 ...

  4. Android之图片加载框架Fresco基本使用(二)

    PS:最近看到很多人都开始写年终总结了,时间过得飞快,又到年底了,又老了一岁. 学习内容: 1.进度条 2.缩放 3.ControllerBuilder,ControllerListener,Post ...

  5. Android 三大图片加载框架的对比——ImageLoader,Picasso,Glide

    一.ImageLaoder介绍 << Universal ImageLoader 是很早开源的图片缓存,在早期被很多应用使用 多线程下载图片,图片可以来源于网络,文件系统,项目文件夹ass ...

  6. Android图片加载框架最全解析(六),探究Glide的自定义模块功能

    不知不觉中,我们的Glide系列教程已经到了第六篇了,距离第一篇Glide的基本用法发布已经过去了半年的时间.在这半年中,我们通过用法讲解和源码分析配合学习的方式,将Glide的方方面面都研究了个遍, ...

  7. Android中常见的图片加载框架

    图片加载涉及到图片的缓存.图片的处理.图片的显示等.而随着市面上手机设备的硬件水平飞速发展,对图片的显示要求越来越高,稍微处理不好就会造成内存溢出等问题.很多软件厂家的通用做法就是借用第三方的框架进行 ...

  8. 一起写一个Android图片加载框架

    本文会从内部原理到具体实现来详细介绍如何开发一个简洁而实用的Android图片加载缓存框架,并在内存占用与加载图片所需时间这两个方面与主流图片加载框架之一Universal Image Loader做 ...

  9. Android项目框架之图片加载框架的选择

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 从Android爆发以后,自定义的控件如EditTextWithDelete.ActionBar.P ...

随机推荐

  1. 关于css中z-index 的应用

    我想很多人在应用中的会碰到这个问题,设置 z-index无效:无论设置为多高的数字都没有效果: 原因是在设置z-index之前必须满足一下两个条件: 1,给设置z-index的元素设置相应的定位值,p ...

  2. 利用http协议实现图片窃取

    在http协议里有一个referer,用来标示站点来源,大家都遇到这样的情况.转载了一篇博客,图片显示不正常,就和头信息里这个有关 原理:在webserver里面.依据http协议里面refered头 ...

  3. iOS开发中一些常用的方法

    1.压缩图片 #pragma mark 处理图片 - (void)useImage:(UIImage *)image { NSLog(@"with-----%f heught-----%f& ...

  4. android学习资料

      在线查看android源码 1. https://github.com/android 2. http://grepcode.com/project/repository.grepcode.com ...

  5. Cisco交换机设置管理IP

    需要准备一根CONSOLE线和带串行接口的电脑. (图1) 用CONSOLE线连接好电脑与交换机(交换机的CONSOLE口一般都有表示). 然后按照图1点“开始→程序→超级终端”会弹出来一个窗口(图2 ...

  6. hdu1002大数相加

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...

  7. MyJFrame(文本)界面的建立

    import java.awt.Color;import java.awt.Component;import java.awt.Container;import java.awt.FlowLayout ...

  8. Java开发之I/O读取文件实例详解

    在java开发或者android开发中,读取文件是不可避免的,以下对java开发中读取文件做了归纳和详解: 1.按字节读取文件内容2.按字符读取文件内容3.按行读取文件内容 4.随机读取文件内容 pa ...

  9. Beyond REST: How to build a HATEOAS API in Java with Spring MVC, Jersey (JAX-RS) and VRaptor

    http://zeroturnaround.com/rebellabs/beyond-rest-how-to-build-a-hateoas-api-in-java-with-spring-mvc-j ...

  10. [整理]Oracle LOCK 机制

    数据库是一个多用户使用的共享资源.当多个用户并发地存取数据时,在数据库中就会产生多个事务同时存取同一数据的情况.若对并发操作不加控制就可能会读取和存储不正确的数据,破坏数据库的一致性.锁机制用于管理对 ...