0

我正在尝试做的事情:

我使用 Android PdfRenderer 类将单个 pdf 页面渲染为位图。(渲染票价不是问题)

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

我的问题? 最好的方法是什么?- 我应该使用带有多个 ImageView 的 RecyclerView - 我应该使用两个带有滚动的 ImageView - 性能很重要,所以应该是高效的

我很高兴有任何意见或想法。

4

1 回答 1

0

不确定渲染部分,但我确实处理过显示多个图像。您可以使用 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();
    }
} 

适配器类中

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

}

于 2017-12-05T05:48:41.050 回答