剛開始以為是listview或者Recyclerview的緩存複用問題,結果研究了半天才知道是Glide圓形頭像CircleImageView的問題。
直接貼代碼,代碼很簡單,直接在Recyclerview的onBinderViewHolder裡面或者Listview的getView裡面把把設定頭像的代碼加上Tag。
String tag = (String) holder.contacts.getTag(); //擷取頭像空間的Tag進行比較
//如果不一樣,則設定為預設頭像/圖檔
if(!TextUtils.equals(datalist.get(position).getMailpath(),tag)) { holder.contacts.setImageResource(R.drawable.addtk);
}
//使用Glide展示頭像
Glide.with(EmailBaseActivity.this)
.load(datalist.get(position).getMailpath())
.into(new SimpleTarget<GlideDrawable>() {
@Override
public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
holder.contacts.setTag(datalist.get(position).getMailpath());
holder.contacts.setImageDrawable(resource);
}
});