gpt4 book ai didi

java - 通过 Fresco 库加载的适配器图像不规则

转载 作者:行者123 更新时间:2023-11-29 04:51:05 25 4
gpt4 key购买 nike

我一直在使用 fresco 库在适配器中加载图像,但图像没有像我预期的那样正确设置。这是我的代码:

 public class HomeListingAdapter_recyler1 extends RecyclerView.Adapter  {
private Context context;
private ArrayList propertyItemList;
private ImageLoader mImageLoader;
public HomeListingAdapter_recyler1(HomeListingActivity_recycler propertyViews, ArrayList propertyItemList) {
Fresco.initialize(propertyViews);
this.propertyItemList = propertyItemList;
this.context = propertyViews;
}
@Override
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.property_item_layout,parent,false);
CustomViewHolder viewHolder = new CustomViewHolder(itemLayoutView);
return viewHolder;
}

@Override
public void onBindViewHolder(final CustomViewHolder holder, final int position) {
mImageLoader = VolleySingletonPattern.getInstance(context).getImageLoader();
holder.txtPropertyName.setText(propertyItemList.get(position).ville);
holder.txtPropertyType.setText(propertyItemList.get(position).bienName);
if(propertyItemList.get(position).pieces.equalsIgnoreCase("0")){
holder.txtPropertySurfaceArea.setText(propertyItemList.get(position).surface+" "+context.getString(R.string.meter_square));
} else { holder.txtPropertySurfaceArea.setText(propertyItemList.get(position).surface+" "+context.getString(R.string.meter_square)+" - "+ propertyItemList.get(position).pieces+" "+context.getResources().getString(R.string.pieces));
}
holder.txtPropertyPrice.setText(propertyItemList.get(position).montantLoyer);
Uri imageUri;
try {
if(!TextUtils.isNullOrEmpty(propertyItemList.get(position).photo)) {
imageUri = Uri.parse(propertyItemList.get(position).photo);
holder.imgPropertyImage.setVisibility(View.VISIBLE);
holder.imgPropertyImage.setImageURI(imageUri);
}
} catch (Exception e) {
}
}
@Override
public int getItemCount() {
return propertyItemList.size();
}
public class CustomViewHolder extends RecyclerView.ViewHolder {
SimpleDraweeView imgPropertyImage;
public TextView txtPropertyName , txtPropertyType , txtPropertySurfaceArea ,txtPropertyPrice;
public CustomViewHolder(View itemView) {
super(itemView);
imgPropertyImage = (SimpleDraweeView) itemView.findViewById(R.id.image_property);
txtPropertyName = (TextView) itemView.findViewById(R.id.txt_property_name);
txtPropertyType = (TextView) itemView.findViewById(R.id.txt_property_type);
txtPropertySurfaceArea = (TextView) itemView.findViewById(R.id.txt_property_surface_piece);
txtPropertyPrice = (TextView) itemView.findViewById(R.id.txt_property_price);
}
}
}

最佳答案

在 xml 中设置默认占位符图像。在您的适配器类中,如果您的照片网址不为空,请将您的照片网址字符串转换为 uri 并将其设置为 view.setImageUri(uri),否则在您的其他部分设置 view.setImageUri(null)。

Uri imageUri;

try {

holder.imgPropertyImage.setVisibility(View.VISIBLE);

if(!TextUtils.isNullOrEmpty(propertyItemList.get(position).photo)) {

imageUri = Uri.parse(propertyItemList.get(position).photo);

holder.imgPropertyImage.invalidate();

holder.imgPropertyImage.setImageURI(imageUri);

}

else{

holder.imgPropertyImage.invalidate();

holder.imgPropertyImage.setImageURI(null);

}

}
catch (Exception e) {
e.printStackTrace();

}

关于java - 通过 Fresco 库加载的适配器图像不规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35379733/

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