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



我要做的事情:

i使用Android PDFrenderer类渲染单个PDF页面。(渲染票价不是问题)

否我想在屏幕上显示整个第一页和第二页的一半。

我的问题?最好的方法是什么? - 我应该使用带有几个imageViews的回收瓶 - 我应该在滚动中使用两个图像视图 - 性能很重要,因此应该是有效的

我很高兴为任何评论或想法。

不确定渲染部分,但我确实与显示多个图像一起工作。您可以使用uris或位图的路径将其传递到适配器类。

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

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

}

相关内容

  • 没有找到相关文章

最新更新