使用universal-image-loader-1.8.6-with-sources加载网络图片

写一个辅助的class,如

public final class Constants {
private Constants() {
}

public static class Config {
public static final boolean DEVELOPER_MODE = false;
}

public static class Extra {
public static final String IMAGES = "com.shengjing360.IMAGES";
public static final String IMAGE_POSITION = "com.shengjing360.IMAGE_POSITION";
}
}

在application的onCreate中进行初始配置

if (Config.DEVELOPER_MODE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyDialog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyDeath().build());
}

在ImageGalleryAdapter中使用,初始化:

protected ImageLoader imageLoader = ImageLoader.getInstance();
DisplayImageOptions options;

this.options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.home_4)
.showImageForEmptyUri(R.drawable.home_4)
.showImageOnFail(R.drawable.home_4)
.cacheInMemory(true)
.cacheOnDisc(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();

调用:

imageLoader.displayImage(url, imageView, options);

你可能感兴趣的:(使用universal-image-loader-1.8.6-with-sources加载网络图片)