从 Canvas 绘制时,不会反映 Webview 的程序化滚动

Programmatic scroll of Webview isn't reflected when drawing from Canvas

我在 draw 方法中从 WebView 中提取帧并以编程方式滚动它。问题是,无论我的位图有多大,我都只能根据其初始尺寸从 WebView 获取输出。 getHeight() returns 的值为 1440,这就是我从 WebView 获得的所有信息,即使我使位图变大 and/or 我滚动 WebView。 这是它的 draw 方法:

@Override
public void draw( Canvas canvas ) {
    int height = getHeight();
    bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    newCanvas = new Canvas(bitmap);
    super.draw(newCanvas);
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
    array.Buffer = stream.toByteArray();
    mPluginInterfaceBitmap.onFrameUpdate(array, width, height);
    stream.reset();
}

我像这样滚动 webview:

mWebView.scrollBy(0,yScrollBy);

我知道它在滚动,因为在后续帧中我检查:

mWebView.getScrollY()

我的XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<com.export.ian.webviewtest android:id="@+id/web_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

我也试过增加 webview 的大小以匹配其 ContentHeight 但这永远行不通,我不确定它如何适用于无限滚动的网站。我希望能够以编程方式滚动 webview 并提取用户在网页中看到的任何内容的框架。

这是稍微滚动后的样子(忽略图片的角度)

终于从 here 找到了答案:

您必须先调用 WebView.enableSlowWholeDocumentDraw() 才能在您的片段中膨胀视图。