1. 程式人生 > >ImageLoader_下載圖片並快取

ImageLoader_下載圖片並快取

private ImageView iv;
private String url="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1503460480074&di=73f55fbd2d7d629dfefbf1ed9ebaf7df&imgtype=0&src=http%3A%2F%2Fwww.fengdu100.com%2Fuploads%2Fallimg%2F170707%2F201345F54-3.png";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super
.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); DisplayImageOptions options=new DisplayImageOptions.Builder() .cacheInMemory(true) .cacheOnDisk(true) .considerExifParams(true) .build(); ImageLoaderConfiguration config=new
ImageLoaderConfiguration.Builder(this) .defaultDisplayImageOptions(options) .memoryCache(new UsingFreqLimitedMemoryCache(2*1024*1024)) .threadPoolSize(3) .diskCache(new UnlimitedDiskCache(new File("F:\\table"))) .diskCacheFileNameGenerator(new
Md5FileNameGenerator()) .build(); ImageLoader.getInstance().init(config); ImageLoader.getInstance().displayImage(url,iv); } private void initView() { iv = (ImageView) findViewById(R.id.iv); }
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.wangaishi20170823_imageloader.MainActivity">

    <ImageView
android:id="@+id/iv"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</LinearLayout>