适配器在使用 Fresco 库时显示错误的图像
Posted
技术标签:
【中文标题】适配器在使用 Fresco 库时显示错误的图像【英文标题】:Adapter showing the wrong images while using Fresco library 【发布时间】:2016-05-20 16:13:45 【问题描述】:我使用 fresco 库在适配器中加载图像。但图像没有像我预期的那样正确设置。这是我的代码。请帮我。提前致谢。
公共类 HomeListingAdapter_recyler1 扩展 RecyclerView.Adapter 私有上下文上下文; 私有 ArrayList propertyItemList; 私有 ImageLoader mImageLoader; 公共 HomeListingAdapter_recyler1(HomeListingActivity_recycler propertyViews, ArrayList propertyItemList) Fresco.initialize(propertyViews); this.propertyItemList = propertyItemList; this.context = propertyViews; @覆盖 public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) 查看 itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.property_item_layout,parent,false); CustomViewHolder viewHolder = new CustomViewHolder(itemLayoutView); 返回视图持有者; @覆盖 public void onBindViewHolder(最终的 CustomViewHolder 持有者,最终的 int 位置) 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); 乌里图像乌里; 尝试 if(!TextUtils.isNullOrEmpty(propertyItemList.get(position).photo)) imageUri = Uri.parse(propertyItemList.get(position).photo); holder.imgPropertyImage.setVisibility(View.VISIBLE); holder.imgPropertyImage.setImageURI(imageUri); 捕捉(异常 e) @覆盖 公共 int getItemCount() 返回propertyItemList.size(); 公共类 CustomViewHolder 扩展 RecyclerView.ViewHolder SimpleDraweeView imgPropertyImage; public TextView txtPropertyName , txtPropertyType , txtPropertySurfaceArea , txtPropertyPrice; 公共CustomViewHolder(查看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);
【问题讨论】:
【参考方案1】:您的 imgPropertyImage 应该是 SimpleDraweeView
,而不是 ImageView。
【讨论】:
嗨,tyronen,感谢您的回复!我错误地发布了代码。现在我已经按照你说的进行了更新,但我仍然在列表项中得到不规则的图像。以上是关于适配器在使用 Fresco 库时显示错误的图像的主要内容,如果未能解决你的问题,请参考以下文章
footer位置的自动适配(主内容不足一屏时显示在最底部,超出一屏时跟随主内容显示)