1、下锅材料:
Gallery—-gallery.setAdapter( ImageLoaderAdapter )
mCache = ImageCache.getInstance(this);
mCache.setCacheMaxSize(1 * 1024 /* mega / 1024 /* kilo */);
2、组织适配器:ImageLoaderAdapter
** gallery.setAdapter(TestData.generateAdapter(
this, mTestData, R.layout.small_thumbnail_item,mCache, 160, 100));
public static ImageLoaderAdapter generateAdapter(
Context context,
TestData data,
int layout,
ImageCache cache,
int width,
int height) {
final SimpleThumbnailAdapter bigAdapter = new SimpleThumbnailAdapter(
context,
data,
layout,
new String[] { "thumb" },
new int[] { R.id.thumb },
new int[] { R.id.thumb });
return new ImageLoaderAdapter(context, bigAdapter, cache, new int[] { R.id.thumb }, width,
height, ImageLoaderAdapter.UNIT_DIP);
}
分析cacha:用到了cache
ImageLoaderAdapter(
context,
cache,
new int[] { R.id.thumb },
width,
height,
ImageLoaderAdapter.UNIT_DIP);
3、获取ImageLoaderAdapter的参数:SimpleThumbnailAdapter
public class SimpleThumbnailAdapter extends SimpleAdapter {
private final Drawable defaultImages[];
private final int[] mImageIDs;
public SimpleThumbnailAdapter(
Context context,
List<? extends Map<String, ?>> data,
int layout, String[] from,
int[] to,
int[] imageIDs) {
super(context, data, layout, from, to);
final View v = LayoutInflater.from(context).inflate(layout, null, false);
defaultImages = new Drawable[imageIDs.length];
mImageIDs = imageIDs;
for (int i = 0; i < mImageIDs.length; i++) {
final ImageView thumb = (ImageView) v.findViewById(imageIDs[i]);
defaultImages[i] = thumb.getDrawable();
}
}