我要做的是:
我使用Android PdfRenderer类将单个pdf页面渲染为位图。 (渲染这样的票价不是问题)
不,我想在屏幕上显示整个第一页和第二页的一半。
我的问题? 这样做的最佳方法是什么? - 我应该使用带有多个ImageView的RecyclerView - 我应该使用滚动两个ImageViews - 性能很重要,因此应该高效
我很高兴有任何意见或想法。
答案 0 :(得分: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());
}
}