itgoyo / AndroidSummary

12 stars 4 forks source link

listview图片复用错位 #84

Open itgoyo opened 5 years ago

itgoyo commented 5 years ago
 //显示教材图片
//        String urlTag = (String) viewHolder.mIv.getTag(R.id.imageloader_uri);
        String imgUrl = courseInfo.get(position).getIMG_URL();

        viewHolder.mIv.setTag(imgUrl);
// 预设一个图片
        viewHolder.mIv.setImageResource(R.drawable.no_photo);

// 通过 tag 来防止图片错位
        if (viewHolder.mIv.getTag() != null && viewHolder.mIv.getTag().equals(imgUrl)) {
            viewHolder.mIv.setTag(null);
//            viewHolder.mIv.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_launchers));
            Glide.with(mContext).load(Talk915App.APP_URL+"/bookImg/"+classInfo.getIMG_URL())//未完整,请补全
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .placeholder(R.drawable.no_photo)
                    .error(R.drawable.no_photo)
                    .dontAnimate()
                    .into(viewHolder.mIv);
        }