gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 12:45:04 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com