Android: Inflating A Layout And Writting It To Pdf Produces A Blank Pdf
when the user selects a share button within an activity, I would like to inflate a layout, populate it, and then write that layout to a pdf using the new printing API. In my fragm
Solution 1:
If my theory is correct -- that your inflated layout still has a width and height of zero -- you can call measure()
and layout()
to manually size and position things:
root.measure(800, 480);
root.layout(0, 0, 800, 480);
Given a View
named root
, this will have it (and its children, if any) fill an 800-pixel wide by 480-pixel high space (e.g., a WVGA device, landscape, full-screen). In your case, you should be able to call getWidth()
and getHeight()
on the Canvas
to determine the sizes to use for measure()
and layout()
.
FWIW, personally, I'd generate HTML and use that for the basis of printing, rather than a layout file. That's one of the techniques I demonstrate in this sample project.
Post a Comment for "Android: Inflating A Layout And Writting It To Pdf Produces A Blank Pdf"