参考 http://www.codeceo.com/article/android-glide-usage.html
public class GlideImgAdapter extends RecyclerView.Adapter<GlideImgAdapter.GlideHolder>{
private List<String> imgList;
private Context context;
public GlideImgAdapter(Context context,List<String> imgList) {
this.imgList = imgList;
this.context = context;
}
@Override
public int getItemCount() {
return this.imgList.size();
}
@Override
public GlideHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new GlideHolder(LayoutInflater.from(context).inflate(R.layout.item_layout,parent,false));
}
@Override
public void onBindViewHolder(GlideHolder holder, int position) {
Glide.with(context).load(this.imgList.get(position))
.placeholder(R.drawable.defualt)
.centerCrop()
.crossFade()
.into(holder.imageView);
}
class GlideHolder extends RecyclerView.ViewHolder{
public ImageView imageView;
public GlideHolder(View itemView) {
super(itemView);
imageView = (ImageView) itemView.findViewById(R.id.img);
}
}
}
List<String> imgList = Arrays.asList(ImageUtil.IMAGES);
mRecyclerView = (RecyclerView) this.findViewById(R.id.recycleview);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
GlideImgAdapter imgAdapter = new GlideImgAdapter(this,imgList);
mRecyclerView.setAdapter(imgAdapter);
public class ImageUtil {
public static final String[] IMAGES = new String[] {
"http://img5.imgtn.bdimg.com/it/u=3586233367,3171193232&fm=11&gp=0.jpg",
"http://www.pptbz.com/pptpic/UploadFiles_6909/201203/2012031220134655.jpg",
"http://scimg.jb51.net/allimg/160813/103-160Q3143110P5.jpg",
"http://www.xxjxsj.cn/article/UploadPic/2009-5/2009530163624615.jpg",
"http://pic24.nipic.com/20121029/5056611_120019351000_2.jpg",
"http://pic26.nipic.com/20130108/9252150_175323515327_2.jpg",
"http://img3.imgtn.bdimg.com/it/u=1164777046,3928203603&fm=11&gp=0.jpg",
"http://pica.nipic.com/2008-03-11/2008311112935830_2.gif",
"http://img.taopic.com/uploads/allimg/130710/267873-130G011000550.jpg",
"http://img5.imgtn.bdimg.com/it/u=3586233367,3171193232&fm=11&gp=0.jpg",
"http://www.pptbz.com/pptpic/UploadFiles_6909/201203/2012031220134655.jpg",
"http://scimg.jb51.net/allimg/160813/103-160Q3143110P5.jpg",
"http://www.xxjxsj.cn/article/UploadPic/2009-5/2009530163624615.jpg",
"http://pic24.nipic.com/20121029/5056611_120019351000_2.jpg",
"http://pic26.nipic.com/20130108/9252150_175323515327_2.jpg",
"http://img3.imgtn.bdimg.com/it/u=1164777046,3928203603&fm=11&gp=0.jpg",
"http://pica.nipic.com/2008-03-11/2008311112935830_2.gif",
"http://img.taopic.com/uploads/allimg/130710/267873-130G011000550.jpg",
"http://img5.imgtn.bdimg.com/it/u=3586233367,3171193232&fm=11&gp=0.jpg",
"http://www.pptbz.com/pptpic/UploadFiles_6909/201203/2012031220134655.jpg",
"http://scimg.jb51.net/allimg/160813/103-160Q3143110P5.jpg",
"http://www.xxjxsj.cn/article/UploadPic/2009-5/2009530163624615.jpg",
"http://pic24.nipic.com/20121029/5056611_120019351000_2.jpg",
"http://pic26.nipic.com/20130108/9252150_175323515327_2.jpg",
"http://img3.imgtn.bdimg.com/it/u=1164777046,3928203603&fm=11&gp=0.jpg",
"http://pica.nipic.com/2008-03-11/2008311112935830_2.gif",
"http://img.taopic.com/uploads/allimg/130710/267873-130G011000550.jpg","http://img5.imgtn.bdimg.com/it/u=3586233367,3171193232&fm=11&gp=0.jpg",
"http://www.pptbz.com/pptpic/UploadFiles_6909/201203/2012031220134655.jpg",
"http://scimg.jb51.net/allimg/160813/103-160Q3143110P5.jpg",
"http://www.xxjxsj.cn/article/UploadPic/2009-5/2009530163624615.jpg",
"http://pic24.nipic.com/20121029/5056611_120019351000_2.jpg",
"http://pic26.nipic.com/20130108/9252150_175323515327_2.jpg",
"http://img3.imgtn.bdimg.com/it/u=1164777046,3928203603&fm=11&gp=0.jpg",
"http://pica.nipic.com/2008-03-11/2008311112935830_2.gif",
"http://img.taopic.com/uploads/allimg/130710/267873-130G011000550.jpg",
"http://img5.imgtn.bdimg.com/it/u=3586233367,3171193232&fm=11&gp=0.jpg",
"http://www.pptbz.com/pptpic/UploadFiles_6909/201203/2012031220134655.jpg",
"http://scimg.jb51.net/allimg/160813/103-160Q3143110P5.jpg",
"http://www.xxjxsj.cn/article/UploadPic/2009-5/2009530163624615.jpg",
"http://pic24.nipic.com/20121029/5056611_120019351000_2.jpg",
"http://pic26.nipic.com/20130108/9252150_175323515327_2.jpg",
"http://img3.imgtn.bdimg.com/it/u=1164777046,3928203603&fm=11&gp=0.jpg",
"http://pica.nipic.com/2008-03-11/2008311112935830_2.gif",
"http://img.taopic.com/uploads/allimg/130710/267873-130G011000550.jpg",
"http://img5.imgtn.bdimg.com/it/u=3586233367,3171193232&fm=11&gp=0.jpg",
"http://www.pptbz.com/pptpic/UploadFiles_6909/201203/2012031220134655.jpg",
"http://scimg.jb51.net/allimg/160813/103-160Q3143110P5.jpg",
"http://www.xxjxsj.cn/article/UploadPic/2009-5/2009530163624615.jpg",
"http://pic24.nipic.com/20121029/5056611_120019351000_2.jpg",
"http://pic26.nipic.com/20130108/9252150_175323515327_2.jpg",
"http://img3.imgtn.bdimg.com/it/u=1164777046,3928203603&fm=11&gp=0.jpg",
"http://pica.nipic.com/2008-03-11/2008311112935830_2.gif",
"http://img.taopic.com/uploads/allimg/130710/267873-130G011000550.jpg",
"http://img5.imgtn.bdimg.com/it/u=3586233367,3171193232&fm=11&gp=0.jpg",
"http://www.pptbz.com/pptpic/UploadFiles_6909/201203/2012031220134655.jpg",
"http://scimg.jb51.net/allimg/160813/103-160Q3143110P5.jpg",
"http://www.xxjxsj.cn/article/UploadPic/2009-5/2009530163624615.jpg",
"http://pic24.nipic.com/20121029/5056611_120019351000_2.jpg",
"http://pic26.nipic.com/20130108/9252150_175323515327_2.jpg",
"http://img3.imgtn.bdimg.com/it/u=1164777046,3928203603&fm=11&gp=0.jpg",
"http://pica.nipic.com/2008-03-11/2008311112935830_2.gif",
"http://img.taopic.com/uploads/allimg/130710/267873-130G011000550.jpg","http://img5.imgtn.bdimg.com/it/u=3586233367,3171193232&fm=11&gp=0.jpg",
"http://www.pptbz.com/pptpic/UploadFiles_6909/201203/2012031220134655.jpg",
"http://scimg.jb51.net/allimg/160813/103-160Q3143110P5.jpg",
"http://www.xxjxsj.cn/article/UploadPic/2009-5/2009530163624615.jpg",
"http://pic24.nipic.com/20121029/5056611_120019351000_2.jpg",
"http://pic26.nipic.com/20130108/9252150_175323515327_2.jpg",
"http://img3.imgtn.bdimg.com/it/u=1164777046,3928203603&fm=11&gp=0.jpg",
"http://pica.nipic.com/2008-03-11/2008311112935830_2.gif",
"http://img.taopic.com/uploads/allimg/130710/267873-130G011000550.jpg"
};
}