PdfDocument Динамически раздувать макет - PullRequest
0 голосов
/ 17 ноября 2018

Я пытаюсь надуть макет в pdf с помощью PdfDocument.Я хочу динамически вставить дочерние элементы в корень, который является TableLayout.Но потомок накладывает корневой вид в созданный PDF.Есть идеи?

Я пытаюсь надуть макет в pdf с помощью PdfDocument.Я хочу динамически вставить дочерние элементы в корень, который является TableLayout.Но потомок накладывает корневой вид в созданный PDF.Есть идеи?

    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 = inflater.inflate(R.layout.pdf_page, null);
                content.measure(800, 1124);
                content.layout(0, 0, 800, 1124);

                View child = inflater.inflate(R.layout.child_row,null);
                child.measure(800, 1124);
                child.layout(0, 0, 800, 1124);

                ((TableLayout)content.findViewById(R.id.pdf)).addView(child);
                content.draw(page.getCanvas());

                    // finish the page
                    document.finishPage(page);

                    document.writeTo(fos);

**Pdf.layout**

    <TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="0,1,2"
    android:id="@+id/pdf">

    <TableRow
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/fullName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="serif"
            android:text="FullName"
            android:textAlignment="center"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/checkIn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="serif"
            android:text="CheckIn"
            android:textAlignment="center"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/checkOut"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="serif"
            android:text="CheckOut"
            android:textAlignment="center"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:textStyle="bold" />

    </TableRow>



</TableLayout>

**Child layout**

<?xml version="1.0" encoding="utf-8"?>

<TableRow
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="FullName"
            android:textAlignment="center"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="CheckIn"
            android:textAlignment="center"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="CheckOut"
            android:textAlignment="center"/>

    </TableRow>

Я получаю это

enter image description here

И я хочу это

enter image description here

...