绘制的WebView成Android的-L画布画布、WebView、Android

2023-09-05 09:43:26 作者:骚年先疯队ヽ

我使用的是Android的打印框架保存的WebView为PDF格式的HTML内容。由于的WebView Android中-L有一个新的方式来呈现的WebView内容,建议到呼叫 enableSlowWholeDocumentDraw()创建任何webviews之前的方法。这将禁用渲染优化将这样的WebView能够使整个HTML页面。

I'm using Android Print Framework to save the HTML Content of the WebView as PDF. Since WebView in Android-L has a new approach to render the WebView content, it is advised to Call enableSlowWholeDocumentDraw() method before creating any webviews. This will disable rendering optimization so WebView will be able to render the whole HTML page.

这里是code绘制的WebView到画布的部分。

Here is the part of the Code to Draw WebView into a Canvas.

PdfDocument.Page page = document.startPage(pageInfo);
mWebView.draw(page.getCanvas());

我打过电话 WebView.enableSlowWholeDocumentDraw()从应用程序,BaseActivity还权后创建的WebView我的片段里面了。但是,这并没有帮助。

I tried calling WebView.enableSlowWholeDocumentDraw() from Application, BaseActivity and also right after and before Creating WebView inside my Fragment. But this didn't help.

我想启用/禁用硬件加速通过设置层类型的软件和硬件,但是这并没有很好的帮助。我还不能得出整个的WebView。只有可见光部分将被吸引到画布上。

I tried enabling/disabling Hardware Acceleration by setting the Layer Type as SOFTWARE and HARDWARE but this didn't help as well. I still cannot draw the whole WebView. Only the Visible portion will be drawn to the Canvas.

有没有人注意到了这种行为?是否有一个解决方案,或这是一个错误?

Has anybody noticed this behaviour ? Is there a solution for that or is this a Bug ?

修改

事实证明,这不是关于 WebView.enableSlowWholeDocumentDraw(),我们仍然在讨论有关问题。这是错误报告。这里是示例应用程序重现该问题。

It turns out that it's not about WebView.enableSlowWholeDocumentDraw() and we are still discussing about the issue. This is the Bug Report. And here is the Sample App to reproduce the issue.

推荐答案

在努力与这一/类似的问题,我自己的年龄。终于找到了解决办法,由于某种原因, webView.draw(page.getCanvas())渲染的全部内容与奇巧,但不与棒棒堂(甚至 enableSlowWholeDocumentDraw())。 但是,使用(webView.capturePicture())。画(page.getCanvas())组合enableSlowWholeDocumentDraw() DOES的棒棒糖工作,尽管 capturePicture()是pcated德$ P $。 需要注意的最后一个潜在的重要的一点是,通常你会看见许多呼叫的OnDraw作为一个web视图加载它的数据,我发现,与棒棒堂我的快照得到采取prematurely(内容已被完全加载之前 - 烦人,甚至在 onPageFinished() webViewClient的回调方法并不能保证这一点) - 我的解决办法是有一个定制的web视图,并在OnDraw中的方法,添加为第一行:如果(this.getContentHeight()== 0)收益; 即也懒得做任何绘图除非有一些适当的内容。 这样,你不应该得到一个空白网页快照 - 尽管从你的描述听起来这可能不会影响你......

Struggled with this/similar issue myself for ages. Finally found a solution, for some reason webView.draw(page.getCanvas()) renders the whole content with KitKat but not with Lollipop (even with enableSlowWholeDocumentDraw()). However, using (webView.capturePicture()).draw(page.getCanvas()) in combination with enableSlowWholeDocumentDraw() DOES work for Lollipop, although capturePicture() is deprecated. A final potentially important point to note is that typically you see many calls to "onDraw" as a webView loads its data and I found that with Lollipop my snapshot was getting taken prematurely (before the content had been fully loaded - annoyingly even the onPageFinished() callback method of webViewClient does not guarantee this!) - my solution was to have a custom webView and in the onDraw method, add this as the FIRST LINE: if(this.getContentHeight() == 0) return; i.e. don't bother to do any drawing unless there is some proper content. That way you should never get a blank page snapshot - although from your description it sounds like this might not be impacting you....

 
精彩推荐
图片推荐