簡體   English   中英

RecyclerView位圖不會顯示所有位圖圖像

[英]RecyclerView Bitmap not show all Bitmap Images

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);

點擊查看圖片

**更新的代碼在我的適配器上**

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

不要忘記檢查圖像路徑是否為空:)

您應該在ViewHolder執行findViewById

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM