listview顯示圖片縮圖的問題
阿新 • • 發佈:2019-01-03
Listview中包含許多不同格式的檔案,對圖片格式生成縮圖顯示。那麼我的問題來了:如果圖片過多,在下滑或者上滑的時候,其他格式的檔案顯示的圖示會亂掉,會顯示成圖片縮圖的樣子,打斷點除錯發現非圖片格式檔案走的是正確的顯示方式,但是實際顯示出來的確是某個圖片縮圖。
附上顯示方法:
final ViewHolderCd holdercd;
if (convertView == null) {
convertView = View.inflate(ct, R.layout.newlist2, null);
holdercd= new ViewHolderCd();
holdercd.rl_gx = (LinearLayout) convertView
.findViewById(R.id.rl_gx);
holdercd.tv_time = (TextView) convertView.findViewById(R.id.tv_pc2);
holdercd.im = (ImageView) convertView.findViewById(R.id.im_list2);
holdercd.cb = (CheckBox) convertView.findViewById(R.id.cb_gxxz);
convertView.setTag(holdercd);
}else{
holdercd=(ViewHolderCd)convertView.getTag();
}
}
FILE_TYPE f_type = Mime_type.get_file_type(path);//將檔案格式歸類
if (f_type == FILE_TYPE.IMG_FILE) {//圖片格式
setImage(holdercd,fileItemList.get(position).getPath());
} else if (f_type == FILE_TYPE.TEXT_FILE) {//文字格式
holdercd.im.setBackgroundResource(R.drawable.ic_txt);
} else if (f_type == FILE_TYPE.AUDIO_FILE) {//音樂格式
holdercd.im.setBackgroundResource(R.drawable.ic_music);
} else if (f_type == FILE_TYPE.MEDIA_FILE) {//視訊格式格式
holdercd.im.setBackgroundResource(R.drawable.ic_video);
} else {
holdercd.im.setBackgroundResource(R.drawable.ic_weizhi);
}
private void setImage(final ViewHolderCd holdercd, String path) {
ImageLoader.loadDrawable(path, 60, 60, new ImageCallBack() {
@Override
public void imageLoaded(Bitmap drawable) {
holdercd.im.setImageBitmap(drawable);
}
}, new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
Bitmap bitmap= (Bitmap) msg.obj;
holdercd.im.setImageBitmap(bitmap);
}
});
}
附上顯示方法:
final ViewHolderCd holdercd;
if (convertView == null) {
convertView = View.inflate(ct, R.layout.newlist2, null);
holdercd= new ViewHolderCd();
holdercd.rl_gx = (LinearLayout) convertView
.findViewById(R.id.rl_gx);
holdercd.tv_time = (TextView) convertView.findViewById(R.id.tv_pc2);
holdercd.im = (ImageView) convertView.findViewById(R.id.im_list2);
holdercd.cb = (CheckBox) convertView.findViewById(R.id.cb_gxxz);
convertView.setTag(holdercd);
}else{
holdercd=(ViewHolderCd)convertView.getTag();
}
}
FILE_TYPE f_type = Mime_type.get_file_type(path);//將檔案格式歸類
if (f_type == FILE_TYPE.IMG_FILE) {//圖片格式
setImage(holdercd,fileItemList.get(position).getPath());
} else if (f_type == FILE_TYPE.TEXT_FILE) {//文字格式
holdercd.im.setBackgroundResource(R.drawable.ic_txt);
} else if (f_type == FILE_TYPE.AUDIO_FILE) {//音樂格式
holdercd.im.setBackgroundResource(R.drawable.ic_music);
} else if (f_type == FILE_TYPE.MEDIA_FILE) {//視訊格式格式
holdercd.im.setBackgroundResource(R.drawable.ic_video);
} else {
holdercd.im.setBackgroundResource(R.drawable.ic_weizhi);
}
private void setImage(final ViewHolderCd holdercd, String path) {
ImageLoader.loadDrawable(path, 60, 60, new ImageCallBack() {
@Override
public void imageLoaded(Bitmap drawable) {
holdercd.im.setImageBitmap(drawable);
}
}, new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
Bitmap bitmap= (Bitmap) msg.obj;
holdercd.im.setImageBitmap(bitmap);
}
});
}