我正在尝试将 RecycleView 添加到 PDF 文档,但它是不可见的。我在 Activity 内部进行了测试,StatisticsViewHolder
它工作正常,所以我确信问题在于设置或 pdf_layout.xml。StatisticsAdapter
RecycleView
RecycleView
此外,我正在正确设置 PDF 文档,因为RecycleView
它是我中唯一pdf_layout.xml
没有显示的元素(为了简单起见,我删除了其他元素)。
设置RecycleView
:
PdfDocument document = new PdfDocument();
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(2250, 1400, 1).create();
PdfDocument.Page page = document.startPage(pageInfo);
LayoutInflater inflater = (LayoutInflater)
getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View content = inflater.inflate(R.layout.pdf_layout, null);
int measureWidth = View.MeasureSpec.makeMeasureSpec(page.getCanvas().getWidth(), View.MeasureSpec.EXACTLY);
int measuredHeight = View.MeasureSpec.makeMeasureSpec(page.getCanvas().getHeight(), View.MeasureSpec.EXACTLY);
content.measure(measureWidth, measuredHeight);
content.layout(0, 0, page.getCanvas().getWidth(), page.getCanvas().getHeight());
RecyclerView recyclerViewPdf = content.findViewById(R.id.recyclerViewPDF);
recyclerViewPdf.setHasFixedSize(true);
double[] statistics = new double[]{0, 0, 0, 0, 0, 0};
recyclerViewPdf.setLayoutManager(new LinearLayoutManager(getActivity()));
pdfStatisticsAdapter = new StatisticsAdapter(getActivity(), statistics);
recyclerViewPdf.setAdapter(pdfStatisticsAdapter);
content.draw(page.getCanvas());
document.finishPage(page);
pdf_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewPDF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout>
我不确定我是否遗漏了什么或者是否RecycleView
不能成为 pdf_layout 的一部分PdfDocument