从RecyclerView中的URL加载图像

huangapple go评论82阅读模式
英文:

Loading Image from URL in RecyclerView

问题

以下是翻译好的内容:

@Override
public void onBindViewHolder(CategoryGridAdapter.ViewHolder holder, final int position) {
    final CategoryGridModel categoryGridModel = categoryGridModels.get(position);
    holder.textView.setText(categoryGridModel.getDescription());
    holder.frameLayout.setBackgroundColor(Color.parseColor(categoryGridModel.getColor()));
    holder.imageView.setImageResource(R.drawable.ic_icon_archary);

    // 使用 Glide 加载图片
    // Glide.with(context).load("http://i.imgur.com/DvpvklR.png").into(holder.imageView);

    // 使用 Picasso 加载图片
    // Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(holder.imageView);

    // 使用 Glide 加载图片(带有占位图)
    // Glide.with(context)
    //      .asBitmap()
    //      .load(categoryGridModel.getImageUrl())
    //      .placeholder(R.drawable.ic_icon_football)
    //      .dontAnimate()
    //      .into(holder.imageView);
    // Log.d("IMAGE URL", categoryGridModel.getImageUrl());

    holder.imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(context, categoryGridModel.getImageUrl(), Toast.LENGTH_SHORT).show();
        }
    });
}
英文:

I am trying to load images from urls using Glide Library, but no image is showing in the imageview, then I tried to load it using Picasso Library, but same issue.
But image is loading properly from drawable folder using R.drawable.image

    @Override
    public void onBindViewHolder(CategoryGridAdapter.ViewHolder holder, final int position) {
        final CategoryGridModel categoryGridModel = categoryGridModels.get(position);
        holder.textView.setText(categoryGridModel.getDescription ());
        holder.frameLayout.setBackgroundColor (Color.parseColor (categoryGridModel.getColor ()));
        holder.imageView.setImageResource (R.drawable.ic_icon_archary);
        // Glide.with(context).load("http://i.imgur.com/DvpvklR.png").into(holder.imageView);
//        Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(holder.imageView);

//        Glide.with(context)
//                .asBitmap()
//                .load(categoryGridModel.getImageUrl())
//                .placeholder(R.drawable.ic_icon_football)
//                .dontAnimate()
//                .into(holder.imageView);
//                 Log.d ("IMAGE URL",categoryGridModel.getImageUrl () );

        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context, categoryGridModel.getImageUrl (), Toast.LENGTH_SHORT).show();
            }
        });
    }

答案1

得分: 1

可能的解决方法如下:

  1. 将glide的with()参数替换为holder.imageView。

  2. 在清单文件中启用clearTextTraffic,或添加网络配置文件。

  3. 移除Glide中的dontAnimate()

英文:

Possible fixes for this problem are:

  1. replace the glide with() param with holder.imageView.

  2. Enable clearTextTraffic in Manifest or add a network config file.

  3. remove dontAnimate() in Glide.

huangapple
  • 本文由 发表于 2020年8月15日 01:17:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63417310.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定