英文:
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
可能的解决方法如下:
-
将glide的with()参数替换为holder.imageView。
-
在清单文件中启用clearTextTraffic,或添加网络配置文件。
-
移除Glide中的
dontAnimate()
。
英文:
Possible fixes for this problem are:
-
replace the glide with() param with holder.imageView.
-
Enable clearTextTraffic in Manifest or add a network config file.
-
remove
dontAnimate()
in Glide.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论