这是昨天改进后的,我测试了下,可以加载图片到5万张,估计5万以上也是没问题的,我只试到5万,其实也没必要这么高,现实中1000左右就差不多了,不过我的应用到100就差不多了,

package com.lanlong.test;

import java.io.File;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

public class AndrodTestActivity extends Activity {
    
    int number = 50000;

Drawable[] array;
    Bitmap [] array2;
    private Map<String, SoftReference<Drawable>> imageCache =
            new HashMap<String, SoftReference<Drawable>>();

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        String iconPath = Environment.getExternalStorageDirectory()
                +"/vpn/Bafangtong/image/weixin.png";
        
//        array = new Drawable[number];//BitmapDrawable 一样

//        array2 = new Bitmap[number];
        File mfile = new File(iconPath);
        Log.i("","mfile.exists() = "+mfile.exists());
        
        Drawable draw = null;
        long timeBegin = System.currentTimeMillis();
        
        for(int i = 0; i < number; i++)

{

Log.e("", "测试第" + (i+1) + "张图片");
            // time = 2second 10000张    8second 50000张  不到1秒,    29ms 100张
//            array[i] = getResources().getDrawable(R.drawable.ic_launcher);//1000 ok
//            array2[i] = BitmapFactory.decodeFile(iconPath);//max 222
//            zoomImg(array2[i], 800, 480);
//            array[i] = Drawable.createFromPath(iconPath);//max 221
//            array[i] = BitmapDrawable.createFromPath(iconPath);//max  221
            
            
         //time = 149second  ,10000张  ; 1second ,100张 ; 901second ,50000张
            addDrawableToCache(""+i, iconPath);
            draw = getDrawableByPath(""+i, iconPath);
//            array[i] = getBitmapByPath(""+i, iconPath);
            Log.i("","draw = "+draw);
            try {
                
//                array[i] = Drawable.createFromStream(
//                        new FileInputStream(iconPath), iconPath);//max 111
                
//                array[i] = BitmapDrawable.createFromStream(
//                        new FileInputStream(iconPath), iconPath);//max 111
                
                
//                array2[i] = BitmapFactory.decodeStream(
//                        new FileInputStream(iconPath));//max 221 ;
//                Log.i("", "array["+i+"] = "+array[i]);
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
        long timeEnd = System.currentTimeMillis();
        Log.v("","time = "+(timeEnd - timeBegin)/1000 +" second");
    }
      public void addDrawableToCache(String id, String path) {
            // 强引用的Bitmap对象
            Drawable drawable = Drawable.createFromPath(path);
            // 软引用的Bitmap对象
            SoftReference<Drawable> softDrawable = new SoftReference<Drawable>(drawable);
            // 添加该对象到Map中使其缓存
            imageCache.put(id, softDrawable);
            Log.w("","add, imageCache.size() = "+imageCache.size());
        }
      
      public Drawable getDrawableByPath(String id, String path) {
            // 从缓存中取软引用的Bitmap对象
            SoftReference<Drawable> softDrawable = imageCache.get(id);
            // 判断是否存在软引用
            if (softDrawable == null) {
                return null;
            }
            // 取出Bitmap对象,如果由于内存不足Bitmap被回收,将取得空
            Drawable drable = softDrawable.get();
            return drable;
        }
}

android加载更多的图片的更多相关文章

  1. Android加载/处理超大图片神器!SubsamplingScaleImageView(subsampling-scale-image-view)【系列1】

    Android加载/处理超大图片神器!SubsamplingScaleImageView(subsampling-scale-image-view)[系列1] Android在加载或者处理超大巨型图片 ...

  2. ajax点击加载更多数据图片(预加载)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. Android UI--自定义ListView(实现下拉刷新+加载更多)

    Android UI--自定义ListView(实现下拉刷新+加载更多) 关于实现ListView下拉刷新和加载更多的实现,我想网上一搜就一堆.不过我就没发现比较实用的,要不就是实现起来太复杂,要不就 ...

  4. [Android] Android 支持下拉刷新、上拉加载更多 的 XRecyclerview

    XRecyclerView一个实现了下拉刷新,滚动到底部加载更多以及添加header功能的的RecyclerView.使用方式和RecyclerView完全一致,不需要额外的layout,不需要写特殊 ...

  5. Android 开发 上拉加载更多功能实现

    实现思维 开始之前先废话几句,Android系统没有提供上拉加载的控件,只提供了下拉刷新的SwipeRefreshLayout控件.这个控件我们就不废话,无法实现上拉刷新的功能.现在我们说说上拉加载更 ...

  6. android 加载图片框架--Glide使用详解

    一.简介 Glide,一个被google所推荐的图片加载库,作者是bumptech.这个库被广泛运用在google的开源项目中,包括2014年的google I/O大会上发布的官方app.(PS:众所 ...

  7. Android学习笔记_51_转android 加载大图片防止内存溢出

    首先来还原一下堆内存溢出的错误.首先在SD卡上放一张照片,分辨率为(3776 X 2520),大小为3.88MB,是我自己用相机拍的一张照片.应用的布局很简单,一个Button一个ImageView, ...

  8. Android之Socket通信、List加载更多、Spinner下拉列表

    Android与服务器的通信方式主要有两种,一是Http通信,一是Socket通信.两者的最大差异在于,http连接使用的是“请求—响应方式”,即在请求时建立连接通道,当客户端向服务器发送请求后,服务 ...

  9. Android ListView加载更多

    先看效果: ListView的footer布局: <?xml version="1.0" encoding="utf-8"?> <Relati ...

随机推荐

  1. 高性能PHP论坛 Carbon Forum

    Carbon Forum,一个高性能的.高安全性的.基于话题的PHP轻论坛. 优秀的架构,高效的代码,每个页面平均执行时间仅为1~5毫秒,同时恰当地使用异步加载技术,在SEO与用户体验间取得平衡. 论 ...

  2. 项目与软件推荐之编辑器-QOwnNotes(刺激自己)

    项目与软件推荐之编辑器-QOwnNotes 今天推荐一款软件 QOwnNotes,是一款普通文本笔记软件.以某个路径为目录,罗列出目录下所有的 md 文件或者 txt 文件. 有如下亮点: 启动速度快 ...

  3. POJ 2976 Dropping tests(二分答案)

    [题目链接]  http://poj.org/problem?id=2976 [题目大意] 给出每门成绩的总分和得分,去除k门成绩之后 使得剩余的成绩分数和除以总分得到的数字最大,要求精度在三位小数之 ...

  4. android-vlc for rtsp build OK

    近期研究 rtsp http stream 流获取方式 vlc over live555  是个很不错的选择,当然了 andorid framework av也是支持rtsp http的,相同不错的选 ...

  5. 10个Laravel4开发者必用扩展包

    Laravel是一个新的基于最新PHP版本号语法,支持IoC等设计模式的高速开发框架.眼下最新版本号为4.2,推荐安装PHP版本号5.5+. 本文列举10个基本软件包,都是开发人员使用Laravel框 ...

  6. OCP prepare 20140628

    1. null if       nvl     nvl2 NULLIF函数 Oracle NULLIF函数语法为NULLIF(表达式1,表达式2),如果表达式1和表达式2相等则返回空值,如果表达式1 ...

  7. Maven命令行创建web项目,并部署到jobss当中(解决No plugin found for prefix 'jboss-as' in the current project and in the plugin groups [org.apache.maven.plugins,问题)

    首件创建项目:此处可参照:http://maven.apache.org/guides/mini/guide-webapp.html mvn archetype:generate -DgroupId= ...

  8. [转]取代cookie的网站追踪技术:”帆布指纹识别”初探

    [前言] 一般情况下,网站或者广告联盟都会非常想要一种技术方式可以在网络上精确定位到每一个个体,这样可以通过收集这些个体的数据,通过分析后更加精准的去推送广告(精准化营销)或其他有针对性的一些活动.C ...

  9. UIlabel添加背景图片

    做UI的时候我们可能想给某个Label添加一个背景图片,但查看的时候会发现好像只有设置背景颜色的方法,不过我们也可以通过这种方式来解决: UIColor *color = [UIColor color ...

  10. 关于新装ubuntu系统update失败和build-essential失败的解决办法

    我是12月4日在新电脑上的vmware-workstation 10 上安装的ubuntu14.04LTS,但安装后再校园环境下总是build-essential失败,上网一查,说是要先update, ...