ImageLoader缓存图片到SD卡+清除缓存
来源:互联网 发布:视频监控软件免费版 编辑:程序博客网 时间:2024/05/16 15:15
//MyApplication
public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); String path = Environment.getExternalStorageDirectory().getPath() + "/RiKao13"; File file = new File(path); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) .memoryCacheExtraOptions(200, 200)//配置内存缓存图片的尺寸 .memoryCacheSize(2 * 1024 * 1024)//配置内存缓存的大小 .threadPoolSize(3)//配置加载图片的线程数 .threadPriority(1000)//配置线程的优先级 .diskCache(new UnlimitedDiskCache(file))//UnlimitedDiskCache 限制这个图片的缓存路径 .diskCacheFileCount(50)//配置sdcard缓存文件的数量 .diskCacheFileNameGenerator(new Md5FileNameGenerator())//MD5这种方式生成缓存文件的名字 .diskCacheSize(50 * 1024 * 1024)//在sdcard缓存50MB .build();//完成 ImageLoader.getInstance().init(config); }}//MainActivity
public class MainActivity extends AppCompatActivity { private ImageView imageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //显示当前页面布局 setContentView(R.layout.activity_main); //获取资源ID imageView = (ImageView) findViewById(R.id.main_image); //缓存 String path = "http://img4.imgtn.bdimg.com/it/u=2720761512,1992761174&fm=26&gp=0.jpg"; //自定义配置 DisplayImageOptions options = new DisplayImageOptions.Builder() .cacheInMemory(true)//让图片进行内存缓存 .cacheOnDisk(true)//让图片进行sdcard缓存 /*.showImageForEmptyUri(R.mipmap.ic_empty)//图片地址有误 .showImageOnFail(R.mipmap.ic_error)//当图片加载出现错误的时候显示的图片 .showImageOnLoading(R.mipmap.loading)//图片正在加载的时候显示的图片*/ .build(); //ImageLoader.getInstance().loadImage(path,options,new Ima);//加载图片 //参数1:加载的图片地址 //参数2:将图片设置到那个图片控件上面 //参数3:加载图片配置选项,意思是指明对这张图片的是否进行缓存(内存、sdcard) ImageLoader.getInstance().displayImage(path, imageView, options); } //清除缓存按钮 public void clearCache(View view){ //清除缓存的方法 ImageLoader.getInstance().clearDiskCache();//清除磁盘缓存 ImageLoader.getInstance().clearMemoryCache();//清除内存缓存 Toast.makeText(this, "清除缓存成功", Toast.LENGTH_SHORT).show(); }}
阅读全文
0 0
- ImageLoader缓存图片到SD卡+清除缓存
- ImageLoader缓存一个网址图片并存到SD卡上
- 图片缓存SD卡,点击清除
- ImageLoader的SD卡缓存
- ViewPager无限轮播,加载网络数据,ImageLoader加载图片并缓存到SD卡上
- ViewPager无限轮播,加载网络数据,ImageLoader加载图片并缓存到SD卡上
- ImageLoader超简单使用并缓存到本地SD卡
- ImageLoader清除缓存
- 图片缓存到SD卡中
- 缓存到SD卡
- 使用ImageLoader缓存图片到SDCARD
- Android开发——webView的缓存清除和将缓存存储到sd卡
- ImageLoader缓存图片
- ImageLoader图片缓存
- ImageLoader缓存图片
- 关于ImageLoader图片缓存
- ImageLoader图片缓存
- ImageLoader三级缓存和清除缓存
- 关于f_open遇见的FR_DISK_ERR问题
- socket C/C++编程(7)server端读取client端键入的数据
- int main(int argc, char *argv[])问题(1)--概念和传数值
- shell判断全部都是数字(shell学习笔记六)
- ASP.NET MVC使用Echarts动态生成图表
- ImageLoader缓存图片到SD卡+清除缓存
- 移动app开发,固定图片div宽高,根据实际图片大小控制图片不变形
- <一>练习 仿AideTeach 软件(android)
- Android APN
- 关于C#迭代器与Unity的Coroutine
- rocketmq注意点
- iOS开发-设置headerInsectionView不悬浮
- Python Qt GUI 环境配置
- android中dp dpi