Android开源代码精选之ImageLoader
Android开发中最常用到的组件,非ImageLoader莫属。
源码地址:https://github.com/nostra13/Android-Universal-Image-Loader
[上代码]:
1. 添加jar包
2. 修改Android Manifest,添加网络请求和写文件权限
01 02 03 04 05 06 07 08 09 | < manifest >
< uses-permission android:name = "android.permission.INTERNET" />
<!-- Include next permission if you want to allow UIL to cache p_w_picpaths on SD card -->
< uses-permission android:name = "android.permission.WRITE_EXTERNAL_STORAGE" />
...
< application android:name = "MyApplication" >
...
</ application > </ manifest > |
3. 修改Application,初始化ImageLoader
01 02 03 04 05 06 07 08 09 10 11 12 | public class MyApplication extends Application {
@Override
public void onCreate() {
super .onCreate();
//
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
...
.build();
ImageLoader.getInstance().init(config);
} } |
3. 可以使用啦
01 02 | // Load p_w_picpath, decode it to Bitmap and display Bitmap in ImageView p_w_picpathLoader.displayImage(p_w_picpathUri, p_w_picpathView); |