RecycleView中的毕加索未加载图像

时间:2019-01-12 03:22:24

标签: android picasso recyclerview-layout

Supp偷窥, 我正在创建一个ImageLiveFeed应用程序,其中图像将从数据库加载到实时数据。我的适配器中的毕加索无法加载图像,我通过将图像放入可绘制文件夹并使用setImageResource进行了手动尝试,并且可以正常工作。这是我的适配器代码。很好,因为我仍在学习Android开发

 public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageHolder> {
        private List<Image> images = new ArrayList<>();
        public static Bitmap bitImg;
        public static Context context;
        @NonNull
        @Override
        public ImageHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
            View view =LayoutInflater.from(viewGroup.getContext())
                    .inflate(R.layout.image_item,viewGroup,false);
            this.context=view.getContext();
            return new ImageHolder(view);

        }

        @Override
        public void onBindViewHolder(@NonNull ImageHolder imageHolder, int i) {
                Image currentView = images.get(i);
                Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageHolder.image);
                /*Glide.with(this.context)
                        .load("http://xtraction.live/wp-content/uploads/2018/05/AK-47-Redline.jpg")
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .into(imageHolder.image);*/
                imageHolder.description.setText(currentView.getDescription());
        }
        @Override
        public int getItemCount() {
            return images.size();
        }
        public void setImages (List<Image> images){
            this.images=images;
            notifyDataSetChanged();
        }

        class ImageHolder extends RecyclerView.ViewHolder{
            private TextView description;
            private ImageView image;

            public ImageHolder(@NonNull View itemView) {
                super(itemView);
                description=itemView.findViewById(R.id.description_id);
                image=itemView.findViewById(R.id.image_id);

            }
        }
    }

1 个答案:

答案 0 :(得分:0)

尝试使用此代码,可能是图像尺寸不合适,无法加载图像,

Picasso.get().load("http://i.imgur.com/DvpvklR.png")
.resize(50, 50)
.centerCrop()
.error(R.drawable.user_placeholder_error)
.into(imageHolder.image);