简体   繁体   English

在可滚动列表中显示多个位图的最佳实践

[英]Best practice for displaying multiple bitmaps in a scrollable list

What I am trying to do: 我正在尝试做的是:

I render single pdf pages to bitmaps using Android PdfRenderer class. 我使用Android PdfRenderer类将单个pdf页面呈现为位图。 (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 -我应该将RecyclerView与多个ImageViews一起使用-我应该将两个ImageViews与滚动一起使用-性能很重要,因此应该高效

I am glad for any comments or ideas. 我很高兴有任何评论或想法。

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. 您可以使用URI或位图的路径将其传递给适配器类。

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

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM