gpt4 book ai didi

android - Universal-Image-Loader:错误的位图附加到 View

转载 作者:行者123 更新时间:2023-11-29 00:26:29 26 4
gpt4 key购买 nike

我注意到这个库有奇怪的行为。当我加载 ListView 时,我总是会看到图像显示在错误的位置。当我滚动列表时,它会神奇地转到正确的位置。我不确定为什么要这样做。

private final LayoutInflater inflater;
private final Context mContext;
protected ImageLoader imageLoader;
private final DisplayImageOptions options;
private final Deals deal1;
private float dpWidth;

public SingleDealRow(LayoutInflater inflater, Context mContext, Deals deal1, float dpWidth){
this.inflater=inflater;
this.mContext=mContext;
this.deal1=deal1;
this.options = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisc(true)
.resetViewBeforeLoading(true)
.build();
this.imageLoader = ImageLoader.getInstance();
this.dpWidth=dpWidth;
}

public View getView(int position, View convertView) {
final ViewHolder holder;
View view;
if (convertView==null){
ViewGroup viewGroup = (ViewGroup)inflater.inflate(R.layout.single_deal_row, null);
holder = new ViewHolder((ImageView)viewGroup.findViewById(R.id.thumbnail),
(TextView)viewGroup.findViewById(R.id.title),
(TextView)viewGroup.findViewById(R.id.price),
(TextView)viewGroup.findViewById(R.id.priceSavings),
(LinearLayout)viewGroup.findViewById(R.id.rightContainer));
viewGroup.setTag(holder);
view = viewGroup;
} else{
view=convertView;
holder = (ViewHolder)convertView.getTag();
}

// holder.text1.getLayoutParams().width=(int) (dpWidth-155);
int CalculatedWidth=holder.text1.getLayoutParams().width+ holder.thumbnail.getLayoutParams().width+holder.text2.getLayoutParams().width;
Log.d("Harnek","actual width is="+(int) (dpWidth));
holder.text1.setText(deal1.title);
holder.text2.setText(deal1.price);
holder.text3.setText(deal1.priceSavings);
holder.thumbnail.setImageBitmap(null);
Log.d("Harnek","title="+holder.text1.getLayoutParams().width+" thumbnail="+holder.thumbnail.getLayoutParams().width+" price="+holder.text2.getLayoutParams().width+" priceSavings="+holder.text3.getLayoutParams().width+
" rightContainer="+holder.rightContainer.getLayoutParams().width);
/*imageLoader.displayImage(deal1.image, holder.thumbnail, options); // TODO change this to manually take care of bitmaps
imageLoader.displayImage(deal2.image, holder.thumbnail2, options);
imageLoader.displayImage(deal3.image, holder.thumbnail3, options);*/

imageLoader.loadImage(deal1.image, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
// Do whatever you want with Bitmap
holder.thumbnail.setImageBitmap(loadedImage);
}
});
return view;
}

public int getViewType() {
// TODO Auto-generated method stub
return 0;
}

public boolean isEnabled() {
// TODO Auto-generated method stub
return false;
}


private static class ViewHolder{
final ImageView thumbnail;
final TextView text1;
final TextView text2;
final TextView text3;
final LinearLayout rightContainer;

private ViewHolder(ImageView thumbnail,TextView text1,TextView text2,TextView text3,LinearLayout rightContainer){
this.thumbnail=thumbnail;
this.text1=text1;
this.text2=text2;
this.text3=text3;
this.rightContainer=rightContainer;
}
}

}

有人知道我在这里做错了什么吗?

最佳答案

尝试使用更简单的代码:

ImageLoader.getInstance().displayImage(url, holder.thumbnail);

并删除 holder.thumbnail.setImageBitmap(null);
希望对您有所帮助。

关于android - Universal-Image-Loader:错误的位图附加到 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18961783/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com