我正在尝试使用 PdfDocument 将布局膨胀为 pdf。在设计视图中,一切看起来都不错,但是在创建 pdf 时,不会保留空格。正如你在图片中看到的那样,我想要空间与第一个完全一样。有什么想法吗?
我正在尝试使用 PdfDocument 将布局膨胀为 pdf。在设计视图中,一切看起来都不错,但是在创建 pdf 时,不会保留空格。正如你在图片中看到的那样,我想要空间与第一个完全一样。有什么想法吗?
// create a new document
PdfDocument document = new PdfDocument();
// crate a page description
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(800, 1124, 1).create();
// start a page
PdfDocument.Page page = document.startPage(pageInfo);
// draw something on the page
View content = MainActivity.this.getLayoutInflater().inflate(R.layout.pdf_page, null);
content.measure(800, 1124);
content.layout(0, 0, 800, 1124);
content.draw(page.getCanvas());
// finish the page
document.finishPage(page);
document.writeTo(fos);
pdf.layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pdf">
<TableRow
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="FullName"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/checkIn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="text"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/checkOut"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="text"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold" />
</TableRow>
</android.support.constraint.ConstraintLayout>
我要这个
但我明白了