Android: inflating a layout and writting it to PDF produces a blank PDF

北城以北 提交于 2019-11-29 14:35:21

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!