java - RecyclerView 位图不显示所有位图图像

标签 java android bitmap android-recyclerview

RecyclerView 位图不显示所有位图图像,仅显示最后一个,但每个项目上显示文本

这是我在项目中使用的适配器代码:

ArrayList<Bitmap> bitmapArrayList;
PathModel pathModel=pathList.get(position);
 holder.videoName= (TextView) myLayoutView.findViewById(R.id.FilePath);

holder.videoThumb= (CircularImageView) 
myLayoutView.findViewById(R.id.VideoThumbnail);
holder.videoName.setText(pathModel.getPath());

holder.videoThumb.setImageBitmap(bitmapArrayList.get(position));
VideoAdapter videoAdapter=new VideoAdapter(this,pathList,bitmapArrayList);
    layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(videoAdapter);

Click to see image

**更新的代码位于我的适配器的此处 **

public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.ViewHolder>{
Context context;

ArrayList<PathModel> pathList;

View myLayoutView;

Bitmap bmThumbnail;

ArrayList<Bitmap> bitmapArrayList;


public VideoAdapter (Context context, ArrayList<PathModel> pathList, ArrayList<Bitmap> bitmapArrayList) {

    this.context = context;

    this.pathList=pathList;

    this.bitmapArrayList=bitmapArrayList;
    }  
@Override

public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    myLayoutView = LayoutInflater.from(context).inflate(R.layout.video_list, 
null);

    return new ViewHolder(myLayoutView);

    }
 @Override

public void onBindViewHolder(ViewHolder myHolder,final int position) {

final ViewHolder holder = (ViewHolder ) myHolder;

PathModel pathModel=pathList.get(position);  

holder.videoName= (TextView) myLayoutView.findViewById(R.id.FilePath);

holder.videoThumb= (CircularImageView) 
myLayoutView.findViewById(R.id.VideoThumbnail);

holder.videoName.setText(pathModel.getPath());

holder.videoThumb.setImageBitmap(bitmapArrayList.get(position));

//    holder.videoThumb.setImageDrawable(new 
BitmapDrawable(context.getResources(),bitmapArrayList.get(position)));
//    holder.videoThumb.setImageResource(R.drawable.ab_add_student);
   //    

holder.videoThumb.setImageURI(Uri.parse(pathList.get(position).getPath()));

   }
@Override
public int getItemCount() {
    return this.pathList.size();
    }
class ViewHolder extends RecyclerView.ViewHolder {

TextView videoName;

CircularImageView videoThumb;

ViewHolder(View itemView) {
    super(itemView);
}
}
}

最佳答案

图像加载在Android中是一项繁重的任务,因此在主线程中加载图像并不好,最好使用Picasso或gild等外部库。

引用链接:https://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en

不要忘记检查图像路径是否为空:)

关于java - RecyclerView 位图不显示所有位图图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44804548/

相关文章:

Android Camera Intent - 内存不足错误和旋转错误

c++ - 如何从函数返回 GDI::Bitmap

java - 使用平面 4 :2:0 YUV full scale pixel format 将图像从字节数组转换为位图

java - SQLite 插入时出现空指针异常

java - 字符串数组 - 不必要的同步?

java - 尝试从私有(private)类获取共享首选项值时出错

java - 试图缩小 Android 中的位图不起作用

java - Junit 5 集成测试 Docker

java - Gradle 错误 "Cannot invoke method buildToolsVersion() on null object"

android - phonegap iOS 文件路径