您的位置:首页 > 其它

Bitmap_多级缓存实现图片加载

2017-07-15 13:44 399 查看
图片缓存多采用内存缓存和硬盘缓存两种方式结合,这都不是新鲜事了 。

鉴于个人有些强迫症 , 写博客意一为了总结 ,二是为了分享,以前走过的路,踩过的坑 ,看过太多复制粘贴不负责任的博客。甚至连签名都不改的 的文章 ,恶心至极 。

图片加载 ,都是采用第三方框架 ,使用方便,性能稳定 ,垃圾回收及时 。包括我自己在项目中也是使用Glide 。

这篇博客是对前三篇博客的一个总结 。 把bitmap相关的知识汇总一下 ,写一个图片加载类 。项目也是看了鸿洋大神的博客 。 做了一些调整 ,因为他当时写的那个类太大  ,不喜欢吧所有的功能都写在一个类里面  。代码是可以直接导入项目的 。不坑,亲测可用,然后代码就不讲解了 ,习惯把注释写的很详细 ;

网络下载图片的工具类

package com.reeman.util;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.util.Log;
import android.widget.ImageView;

import com.reeman.util.ImageSizeUtil.ImageSize;

public class DownloadUtils {

/**
* 根据url下载图片在指定的文件
*
* @param urlStr
* @param file
* @return
*/
public static boolean downloadImgByUrl(String urlStr, File file) {
FileOutputStream fos = null;
InputStream is = null;
try {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

is = conn.getInputStream();
fos = new FileOutputStream(file);
byte[] buf = new byte[512];
int len = 0;
while ((len = is.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fos.flush();
return true;
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (is != null)
is.close();
} catch (IOException e) {
}

try {
if (fos != null)
fos.close();
} catch (IOException e) {
}
}

return false;

}

/**
* 根据url下载图片在指定的文件
*
* @param urlStr
* @param file
* @return
*/
public static Bitmap downloadImgByUrl(String urlStr, ImageView imageview) {
FileOutputStream fos = null;
InputStream is = null;
try {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
is = new BufferedInputStream(conn.getInputStream());
is.mark(is.available());

Options opts = new Options();
opts.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeStream(is, null, opts);

// 获取imageview想要显示的宽和高
ImageSize imageViewSize = ImageSizeUtil.getImageViewSize(imageview);
opts.inSampleSize = ImageSizeUtil.caculateInSampleSize(opts,
imageViewSize.width, imageViewSize.height);

opts.inJustDecodeBounds = false;
is.reset();
bitmap = BitmapFactory.decodeStream(is, null, opts);

conn.disconnect();
return bitmap;

} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (is != null)
is.close();
} catch (IOException e) {
}

try {
if (fos != null)
fos.close();
} catch (IOException e) {
}
}
return null;
}
}


网络图片网址数组
package com.reeman.util;

public class Images
{

public final static String[] imageThumbUrls = new String[] {
"http://img.my.csdn.net/uploads/201407/26/1406383299_1976.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383291_6518.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383291_8239.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383290_9329.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383290_1042.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383275_3977.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383265_8550.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383264_3954.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383264_4787.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383264_8243.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383248_3693.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383243_5120.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383242_3127.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383242_9576.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383242_1721.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383219_5806.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383214_7794.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383213_4418.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383213_3557.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383210_8779.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383172_4577.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383166_3407.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383166_2224.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383166_7301.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383165_7197.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383150_8410.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383131_3736.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383130_5094.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383130_7393.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383129_8813.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383100_3554.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383093_7894.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383092_2432.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383092_3071.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383091_3119.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383059_6589.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383059_8814.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383059_2237.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383058_4330.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383038_3602.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382942_3079.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382942_8125.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382942_4881.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382941_4559.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382941_3845.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382924_8955.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382923_2141.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382923_8437.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382922_6166.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382922_4843.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382905_5804.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382904_3362.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382904_2312.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382904_4960.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382900_2418.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382881_4490.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382881_5935.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382880_3865.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382880_4662.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382879_2553.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382862_5375.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382862_1748.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382861_7618.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382861_8606.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382861_8949.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382841_9821.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382840_6603.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382840_2405.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382840_6354.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382839_5779.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382810_7578.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382810_2436.jpg",
"http://img.my.csdn.net/uploads/201407/26/14063
4000
82809_3883.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382809_6269.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382808_4179.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382790_8326.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382789_7174.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382789_5170.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382789_4118.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382788_9532.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382767_3184.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382767_4772.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382766_4924.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382766_5762.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406382765_7341.jpg" };
}

图片尺寸获取相关类,以及图片压缩类

package com.reeman.util;

import java.lang.reflect.Field;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.util.DisplayMetrics;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;

public class ImageSizeUtil {

/**
* 根据图片需要显示的宽和高对图片进行压缩
*
* @param path
* @param width
* @param height
* @return
*/
public static Bitmap decodeSampledBitmapFromPath(String path, int width,
int height) {
// 获得图片的宽和高,并不把图片加载到内存中
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);

options.inSampleSize = ImageSizeUtil.caculateInSampleSize(options,
width, height);

// 使用获得到的InSampleSize再次解析图片
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeFile(path, options);
return bitmap;
}

/**
* 根据需求的宽和高以及图片实际的宽和高计算SampleSize
*
* @param options
* @param width
* @param height
* @return
*/
public static int caculateInSampleSize(Options options, int reqWidth,
int reqHeight) {
int width = options.outWidth;
int height = options.outHeight;

int inSampleSize = 1;

if (width > reqWidth || height > reqHeight) {
int widthRadio = Math.round(width * 1.0f / reqWidth);
int heightRadio = Math.round(height * 1.0f / reqHeight);

inSampleSize = Math.max(widthRadio, heightRadio);
}

return inSampleSize;
}

/**
* 根据ImageView获适当的压缩的宽和高
*
* @param imageView
* @return
*/
public static ImageSize getImageViewSize(ImageView imageView) {

ImageSize imageSize = new ImageSize();
DisplayMetrics displayMetrics = imageView.getContext().getResources()
.getDisplayMetrics();
LayoutParams lp = imageView.getLayoutParams();
int width = imageView.getWidth();// 获取imageview的实际宽度
if (width <= 0) {
width = lp.width;// 获取imageview在layout中声明的宽度
}
if (width <= 0) {
width = getImageViewFieldValue(imageView, "mMaxWidth");
}
if (width <= 0) {
width = displayMetrics.widthPixels;
}

int height = imageView.getHeight();// 获取imageview的实际高度
if (height <= 0) {
height = lp.height;// 获取imageview在layout中声明的宽度
}
if (height <= 0) {
height = getImageViewFieldValue(imageView, "mMaxHeight");// 检查最大值
}
if (height <= 0) {
height = displayMetrics.heightPixels;
}
imageSize.width = width;
imageSize.height = height;

return imageSize;
}

public static class ImageSize {
int width;
int height;
}

/**
* 通过反射获取imageview的某个属性值
*
* @param object
* @param fieldName
* @return
*/
private static int getImageViewFieldValue(Object object, String fieldName) {
int value = 0;
try {
Field field = ImageView.class.getDeclaredField(fieldName);
field.setAccessible(true);
int fieldValue = field.getInt(object);
if (fieldValue > 0 && fieldValue < Integer.MAX_VALUE) {
value = fieldValue;
}
} catch (Exception e) {
}
return value;

}

}


封装图片相关属性
package com.reeman.util;

import android.graphics.Bitmap;
import android.widget.ImageView;

public class ImgBeanHolder {

private Bitmap bitmap;
private ImageView imageView;
private String path;

public ImgBeanHolder() {
super();
}

public ImgBeanHolder(Bitmap bitmap, ImageView imageView, String path) {
super();
this.bitmap = bitmap;
this.imageView = imageView;
this.path = path;
}

public Bitmap getBitmap() {
return bitmap;
}

public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}

public ImageView getImageView() {
return imageView;
}

public void setImageView(ImageView imageView) {
this.imageView = imageView;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

}


内存缓存类

package com.reeman.util;

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

/***
* 内存缓存类
*
* @author reeman
*
*/
public class LrucacheUtil {

/**
* 图片缓存的核心对象
*/
private LruCache<String, Bitmap> mLruCache;
// 获取我们应用的最大可用内存
int maxMemory = (int) Runtime.getRuntime().maxMemory();
int cacheMemory = maxMemory / 8;

public LrucacheUtil() {
// 缓存初始化
mLruCache = new LruCache<String, Bitmap>(cacheMemory) {
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight();
}
};
}

/**
* 将图片加入LruCache
*
* @param path
* @param bm
*/
public void addBitmapToLruCache(String path, Bitmap bm) {
if (getBitmapFromLruCache(path) == null) {
if (bm != null)
mLruCache.put(path, bm);
}
}

/**
* 根据path在缓存中获取bitmap
*
* @param key
* @return
*/
public Bitmap getBitmapFromLruCache(String key) {
if (key != null) {
return mLruCache.get(key);
}
return null;
}

}


MD5加密解密类
package com.reeman.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 {

/**
* 利用签名辅助类,将字符串字节数组
*
* @param str
* @return
*/
public static String md5(String str) {
byte[] digest = null;
try {
MessageDigest md = MessageDigest.getInstance("md5");
digest = md.digest(str.getBytes());
return bytes2hex02(digest);

} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}

/**
* 方式二
*
* @param bytes
* @return
*/
public static String bytes2hex02(byte[] bytes) {
StringBuilder sb = new StringBuilder();
String tmp = null;
for (byte b : bytes) {
// 将每个字节与0xFF进行与运算,然后转化为10进制,然后借助于Integer再转化为16进制
tmp = Integer.toHexString(0xFF & b);
if (tmp.length() == 1)// 每个字节8为,转为16进制标志,2个16进制位
{
tmp = "0" + tmp;
}
sb.append(tmp);
}

return sb.toString();

}

}


最后是图片加载类
package com.reeman.util;

import java.io.File;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.LinkedList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.v4.util.LruCache;
import android.util.Log;
import android.widget.ImageView;

import com.reeman.util.ImageSizeUtil.ImageSize;

public class ImageLoader {
private static ImageLoader mInstance;
/**
* 线程池
*/
private ExecutorService mThreadPool;
private static final int DEAFULT_THREAD_COUNT = 1;
/**
* 队列的调度方式
*/
private Type mType = Type.LIFO;
/**
* 任务队列
*/
private LinkedList<Runnable> mTaskQueue;
/**
* 后台轮询线程
*/
private Thread mPoolThread;
private Handler mPoolThreadHandler;
/**
* UI线程中的Handler
*/
private Handler mUIHandler;

private Semaphore mSemaphorePoolThreadHandler = new Semaphore(0);
private Semaphore mSemaphoreThreadPool;

private boolean isDiskCacheEnable = true;

private static final String TAG = "ImageLoader";

public enum Type {
FIFO, LIFO;
}

private ImageLoader(int threadCount, Type type) {
init(threadCount, type);
}

/**
* 初始化
*
* @param threadCount
* @param type
*/
LrucacheUtil lrucacheUtil;

private void init(int threadCount, Type type) {
initBackThread();
lrucacheUtil = new LrucacheUtil();
// 创建线程池
mThreadPool = Executors.newFixedThreadPool(threadCount);
mTaskQueue = new LinkedList<Runnable>();
mType = type;
mSemaphoreThreadPool = new Semaphore(threadCount);
}

/**
* 初始化后台轮询线程
*/
private void initBackThread() {
// 后台轮询线程
mPoolThread = new Thread() {
@Override
public void run() {
Looper.prepare();
mPoolThreadHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
// 线程池去取出一个任务进行执行
mThreadPool.execute(getTask());
try {
mSemaphoreThreadPool.acquire();
} catch (InterruptedException e) {
}
}
};
// 释放一个信号量
mSemaphorePoolThreadHandler.release();
Looper.loop();
};
};
mPoolThread.start();
}

public static ImageLoader getInstance() {
if (mInstance == null) {
synchronized (ImageLoader.class) {
if (mInstance == null) {
mInstance = new ImageLoader(DEAFULT_THREAD_COUNT, Type.LIFO);
}
}
}
return mInstance;
}

public static ImageLoader getInstance(int threadCount, Type type) {
if (mInstance == null) {
synchronized (ImageLoader.class) {
if (mInstance == null) {
mInstance = new ImageLoader(threadCount, type);
}
}
}
return mInstance;
}

/**
* 根据path为imageview设置图片
*
* @param path
* @param imageView
*/
public void loadImage(final String path, final ImageView imageView,
final boolean isFromNet) {
imageView.setTag(path);
if (mUIHandler == null) {
mUIHandler = new Handler() {
public void handleMessage(Message msg) {
// 获取得到图片,为imageview回调设置图片
ImgBeanHolder holder = (ImgBeanHolder) msg.obj;
Bitmap bm = holder.getBitmap();
ImageView imageview = holder.getImageView();
String path = holder.getPath();
// 将path与getTag存储路径进行比较
if (imageview.getTag().toString().equals(path)) {
imageview.setImageBitmap(bm);
}
};
};
}

// 根据path在缓存中获取bitmap
Bitmap bm = lrucacheUtil.getBitmapFromLruCache(path);

if (bm != null) {
refreashBitmap(path, imageView, bm);
} else {
addTask(buildTask(path, imageView, isFromNet));
}

}

/**
* 根据传入的参数,新建一个任务
*
* @param path
* @param imageView
* @param isFromNet
* @return
*/
private Runnable buildTask(final String path, final ImageView imageView,
final boolean isFromNet) {
return new Runnable() {
@Override
public void run() {
Bitmap bm = null;
if (isFromNet) {
File file = getDiskCacheDir(imageView.getContext(),
MD5.md5(path));
if (file.exists()) {
bm = loadImageFromLocal(file.getAbsolutePath(),
imageView);
} else {
if (isDiskCacheEnable) {
// 检测是否开启硬盘缓存
boolean downloadState = DownloadUtils
.downloadImgByUrl(path, file);
if (downloadState) {
bm = loadImageFromLocal(file.getAbsolutePath(),
imageView);
}
} else {
// 没有开启硬盘缓存,直接去下载图片
bm = DownloadUtils.downloadImgByUrl(path,
imageView);
}
}
} else {
bm = loadImageFromLocal(path, imageView);
}
// 3、把图片加入到缓存
lrucacheUtil.addBitmapToLruCache(path, bm);
refreashBitmap(path, imageView, bm);
mSemaphoreThreadPool.release();
}

};
}

private Bitmap loadImageFromLocal(final String path,
final ImageView imageView) {
Bitmap bm;
// 加载图片
// 图片的压缩
// 1、获得图片需要显示的大小
ImageSize imageSize = ImageSizeUtil.getImageViewSize(imageView);
// 2、压缩图片
bm = ImageSizeUtil.decodeSampledBitmapFromPath(path, imageSize.width,
imageSize.height);
return bm;
}

/**
* 从任务队列取出一个方法
*
* @return
*/
private Runnable getTask() {
if (mType == Type.FIFO) {
return mTaskQueue.removeFirst();
} else if (mType == Type.LIFO) {
return mTaskQueue.removeLast();
}
return null;
}

private void refreashBitmap(final String path, final ImageView imageView,
Bitmap bm) {
Message message = Message.obtain();
ImgBeanHolder holder = new ImgBeanHolder();
holder.setBitmap(bm);
holder.setPath(path);
holder.setImageView(imageView);
message.obj = holder;
mUIHandler.sendMessage(message);
}

private synchronized void addTask(Runnable runnable) {
mTaskQueue.add(runnable);
try {
if (mPoolThreadHandler == null)
mSemaphorePoolThreadHandler.acquire();
} catch (InterruptedException e) {
}
mPoolThreadHandler.sendEmptyMessage(0x110);
}

/**
* 获得缓存图片的地址
*
* @param context
* @param uniqueName
* @return
*/
public File getDiskCacheDir(Context context, String uniqueName) {
String cachePath;
if (Environment.MEDIA_MOUNTED.equals(Environment
.getExternalStorageState())) {
cachePath = context.getExternalCacheDir().getPath();
} else {
cachePath = context.getCacheDir().getPath();
}
return new File(cachePath + File.separator + uniqueName);
}
}


最后是主界面的调用方法
package com.reeman;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import com.reeman.util.ImageLoader;
import com.reeman.util.ImageLoader.Type;
import com.reeman.util.Images;

public class MainActivity extends Activity {
private GridView mGridView;
private String[] mUrlStrs = Images.imageThumbUrls;
private ImageLoader mImageLoader;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_list_imgs);
setUpAdapter();
}

private void setUpAdapter() {
mImageLoader = ImageLoader.getInstance(3, Type.LIFO);
mGridView = (GridView) findViewById(R.id.id_gridview);
mGridView.setAdapter(new ListImgItemAdaper(MainActivity.this, 0,
mUrlStrs));

}

private class ListImgItemAdaper extends ArrayAdapter<String> {

public ListImgItemAdaper(Context context, int resource, String[] datas) {
super(MainActivity.this, 0, datas);
Log.e("TAG", "ListImgItemAdaper");
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = MainActivity.this.getLayoutInflater().inflate(
R.layout.item_fragment_list_imgs, parent, false);
}
ImageView imageview = (ImageView) convertView
.findViewById(R.id.id_img);
imageview.setImageResource(R.drawable.pictures_no);
mImageLoader.loadImage(getItem(position), imageview, true);
return convertView;
}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐