Java 希望屏幕分别显示recyclerView的每个视图吗

Java 希望屏幕分别显示recyclerView的每个视图吗,java,android,listview,Java,Android,Listview,回收视图的OnBind: @Override public void onBindViewHolder(final ItemViewHolder holder, final int position) { holder. tv_bill_no.setText(context.getString(R.string.bill_no_display , String.valueOf(12)) ); holder.tv_total_amt_label.setBackground(

回收视图的OnBind:

@Override
public void onBindViewHolder(final ItemViewHolder holder, final int position)
{
  holder. tv_bill_no.setText(context.getString(R.string.bill_no_display , 
    String.valueOf(12))  );
    holder.tv_total_amt_label.setBackground(context.getResources().getDrawable(R.drawable.textline));
    holder.lv_product_sub_totals.setEmptyView(holder.emptyview);
    Typeface typeface=Typeface.createFromAsset(context.getAssets(),"Capture_it.ttf");
    holder.tv_dist_name.setTypeface(typeface);
    holder.tv_generate.setTypeface(typeface);
    holder.btn_generate_pdf.setVisibility(View.GONE);
   // itemView.setVisibility(View.GONE);
    holder.btn_generate.setVisibility(View.GONE);
    holder.btn_share.setVisibility(View.GONE);

    holder.ll.setDrawingCacheEnabled(true);
    // ImageView iv = (ImageView) rootview.findViewById(R.id.bdf_iv_bill);

    Bitmap bm = Utility.screenShot(holder.ll);
    bitmap_pdf_pages.add(bm);

    Log.e("width",""+holder.ll.getWidth());

   }
这是一个错误
java.lang.IllegalArgumentException:宽度和高度必须大于0


我正在做的是在
OnBind
中,我正在为每个视图拍摄
屏幕截图
,并将其添加到
ArrayList
中,但我无法这样做。我想要一个解决方案,我可以在
列表视图的
视图的
屏幕截图
,而不是一次完成。其他意见也被接受。

它抛出了一个错误,因为
View.getHeight()
(我假设它正在
实用程序中使用。屏幕截图(holder.ll)
)只有在测量完视图后,在OnBindViewHolder上才有值,而这还没有发生

因此,您必须手动强制测量并使用
view.getMeasuredHeight()
,在“拍摄屏幕截图”之前使用与axml中定义的约束相同的约束


例如,我的宽度和高度测量值为300

View u = holder.ll;
holder.ll.measure(View.MeasureSpec.makeMeasureSpec(300, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(300, View.MeasureSpec.EXACTLY));
u.setDrawingCacheEnabled(true);
int totalHeight = holder.ll.getMeasuredHeight();
int totalWidth = holder.ll.getMeasuredWidth();
u.layout(0, 0, totalWidth, totalHeight);    
u.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(u.getDrawingCache());             
u.setDrawingCacheEnabled(false);
资料来源:


HIH

我明白你的观点,我会尝试给出一个固定的高度和宽度(尽管这可能是一个问题,因为不是所有的
视图都是
相同的尺寸
),明天给你反馈:)这不是关于固定高度与否,而是关于在拍摄截图之前进行测量。例如,最多可以使用View.MeasureSpec.AT_设置“包装内容”。按照源代码中的链接进行操作,并在那里对其进行解释或检查。希望它能有所帮助:对于这个例子,我的宽度和高度测量值为
300
。实际上300是多少?好吧,它是以像素为单位的,所以如果你想要dp,只需对设备显示密度进行计算,如