Best practice for displaying multiple bitmaps in a scrollable list

576 views Asked by At

What I am trying to do:

I render single pdf pages to bitmaps using Android PdfRenderer class. (Rendering so fare is not the issue)

No I want to display the on the screen the entire first page and half of the second page.

My question? What is the best approach to do that? - Should I use a RecyclerView with several ImageViews - Should I use two ImageViews with scrolling - Performance matters, so should be efficient

I am glad for any comments or ideas.

1

There are 1 answers

0
Harshita On

Not sure about the rendering part, but I did work with displaying multiple images. You can use URIs or path of a bitmap to pass it to the adapter class.

 public class MainActivity extends Activity
   {
   ArrayList<String> list; //get the path of a bitmap
    Bitmap bitmap;
     RecyclerView horizontal_rv;
    RecyclerViewAdapter recycleViewAdapter;
    recyvlerview= (RecyclerView);
    LinearLayoutManager horizontal_lm;

    findViewById(R.id.horizontal_recycler_view);//initializing the recyclerview

    horizontal_lm = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL, false); // calling the layout manager

    horizontal_rv.setLayoutManager(horizontal_lm); //setting the layout 
      manager

  horizontal_rv= new RecyclerViewAdapter(list); // initializing the adapter, passing the list

   horizontal_rv.setAdapter(recycleViewAdapter);
       }
       // get image from the gallery
       @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == ImagePicker.IMAGE_PICKER_REQUEST_CODE && resultCode == RESULT_OK && data != null) {
        List<String> mPaths = (List<String>) data.getSerializableExtra(ImagePicker.EXTRA_IMAGE_PATH);
        for(String path:mPaths)
        {
            horizontalList.add(path);
            Log.e("horizontallist size", String.valueOf(horizontalList.size()));
        }
        Log.e("tag", String.valueOf(mPaths.size()));
        recycleViewAdapter.notifyDataSetChanged();
    }
} 

In the adapter class

   public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> implements Serializable{

private List<String> horizontalList;
public class MyViewHolder extends RecyclerView.ViewHolder {
    public ImageView image_result;

    public MyViewHolder(View view) {
        super(view);
        image_result = (ImageView) view.findViewById(R.id.image_result);
    }
}

public RecyclerViewAdapter(ArrayList<String> horizontalList) {
    this.horizontalList = horizontalList;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.recyclerview_item_row, parent,false);

    return new MyViewHolder(itemView);

}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
   holder.image_result.setImageURI(Uri.parse(horizontalList.get(position)));  // setting image in the recycler view
    holder.image_result.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           // do anything with the image that is clicked
        }
    });
}


@Override
public int getItemCount() {
    return horizontalList.size();
}
public void removeAt(int position) {
    horizontalList.remove(position);
    notifyItemRemoved(position);
    notifyItemRangeChanged(position, horizontalList.size());
}

}