public class MainActivity extends AppCompatActivity { private ImageView image; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image = (ImageView) findViewById(R.id.images); } public void button1(View view){ DisplayImageOptions options=new DisplayImageOptions.Builder() .cacheInMemory(true) .cacheOnDisk(true) .showImageOnLoading(R.mipmap.ic_launcher) .build(); String path="http://img.juhe.cn/cookbook/s/1/92_04f90c14513aa139.jpg"; ImageLoader.getInstance().displayImage(path,image,options); } public void button2(View view){ File getfile=new File(Environment.getExternalStorageDirectory().getPath()+"/HHH"); if (getfile.isDirectory()){ File[] files=getfile.listFiles(); for (int i=0;i<files.length;i++){ files[i].delete(); } } getfile.delete(); } }public class Myapp extends Application { @Override public void onCreate() { super.onCreate(); String path = Environment.getExternalStorageDirectory().getPath()+"/HHH"; File file = new File(path); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) .memoryCacheExtraOptions(480,800)//配置内存缓存图片的尺寸 .memoryCacheSize(2 * 1024 * 1024)//配置内存缓存的大小 例如 : 2* 1024 * 1024 = 2MB .threadPoolSize(3)//配置加载图片的线程数 .threadPriority(100)//配置线程的优先级 .diskCache(new UnlimitedDiskCache(file))//UnlimitedDiskCache 限制这个图片的缓存路径 .diskCacheSize(50 * 1024 * 1024)//在sdcard缓存50MB .diskCacheFileNameGenerator(new Md5FileNameGenerator())//MD5这种方式生成缓存文件的名字 .diskCacheFileCount(20)//配置sdcard缓存文件的数量 .build();//配置构建完成 ImageLoader.getInstance().init(config); } }
图片缓存SD卡,点击清除
最新推荐文章于 2021-05-29 01:48:53 发布