用AsyncTask加载图片
private GridAdapter3 gridAdapter;
public ImageLoadTask(Context context,GridAdapter3 gridAdapter)
{
this.gridAdapter=gridAdapter;
}
@Override
protected Void doInBackground(String... params) {
for(int i=0;i<gridAdapter.getCount();i++)
{
ImageInfo imageInfo= (ImageInfo) gridAdapter.getItem(i);
String imagePath = imageInfo.getImagePath();
Bitmap bitmap = getImagefromNetWork(imagePath);
imageInfo.setBitmap(bitmap);
//吧下载好的信息传出去
publishProgress();
}
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
Log.e("Main","刷新");
//上面只是把bitmap放到了实体类里面 此处刷新可在界面上显示
gridAdapter.notifyDataSetChanged();
}
使用谷歌工具加载图片
compile ‘com.github.bumptech.glide:glide:3.7.0’
其中placeholder占位符 centerCrop居中裁剪 然后可以缓存 最后放到容器中
Glide.with(context).load(imageInfo.getImagePath()).
placeholder(R.mipmap.ic_launcher).centerCrop().into(holder.imageView);