11

我有一个包含 WebView 作为其子项的画廊,当我滚动画廊时,我收到以下警告,

'04-07 19:35:37.409: WARN/webcore(664): Can't get the viewWidth after the first layout
 04-07 19:35:37.470: WARN/webcore(664): skip viewSizeChanged as w is 0'

这个警告指的是什么?[我没有硬编码任何布局参数。]

任何关于为什么会发生此警告的信息都会非常有帮助......

这些也被打印出来了

04-15 11:10:13.202: DEBUG/webviewglue(617): nativeDestroy view: 0x257f40
04-15 11:10:13.243: DEBUG/webviewglue(617): nativeDestroy view: 0x25d680
04-15 11:10:13.292: DEBUG/webviewglue(617): nativeDestroy view: 0x240688
04-15 11:10:13.332: DEBUG/webviewglue(617): nativeDestroy view: 0x249918
04-15 11:10:13.373: DEBUG/webviewglue(617): nativeDestroy view: 0x226608
04-15 11:10:13.423: DEBUG/webviewglue(617): nativeDestroy view: 0x21e418
04-15 11:10:13.482: DEBUG/webviewglue(617): nativeDestroy view: 0x23a4e8
04-15 11:10:13.533: DEBUG/webviewglue(617): nativeDestroy view: 0x235c68
04-15 11:10:13.572: DEBUG/webviewglue(617): nativeDestroy view: 0x212a28

提前致谢。

4

2 回答 2

1

您的 viewSize 已更改并正在通知这一点,由于某种原因(可能缩放),宽度值为 0。如此处所示:

// notify webkit that our virtual view size changed size (after inv-zoom)
            private void viewSizeChanged(int w, int h, int textwrapWidth,
                    float scale, int anchorX, int anchorY, boolean ignoreHeight) {
                if (DebugFlags.WEB_VIEW_CORE) {
                    Log.v(LOGTAG, "viewSizeChanged w=" + w + "; h=" + h
                            + "; textwrapWidth=" + textwrapWidth + "; scale="
                            + scale);
                }
                if (w == 0) {
                    Log.w(LOGTAG, "skip viewSizeChanged as w is 0");
                    return;
                }
                int width = w;
                if (mSettings.getUseWideViewPort()) {
                    if (mViewportWidth == -1) {
                        if (mSettings.getLayoutAlgorithm() == WebSettings.LayoutAlgorithm.NORMAL) {
                            width = WebView.DEFAULT_VIEWPORT_WIDTH;
                        } else {
                            /*
                             * if a page's minimum preferred width is wider than the
                             * given "w", use it instead to get better layout result. If
                             * we start a page with MAX_ZOOM_WIDTH, "w" will be always
                             * wider. If we start a page with screen width, due to the
                             * delay between {@link #didFirstLayout} and
                             * {@link #viewSizeChanged},
                             * {@link #nativeGetContentMinPrefWidth} will return a more
                             * accurate value than initial 0 to result a better layout.
                             * In the worse case, the native width will be adjusted when
                             * next zoom or screen orientation change happens.
                             */
                            width = Math.min(WebView.sMaxViewportWidth, Math
                                    .max(w, Math.max(
                                            WebView.DEFAULT_VIEWPORT_WIDTH,
                                            nativeGetContentMinPrefWidth())));
                        }
                    } else if (mViewportWidth > 0) {
                        width = Math.max(w, mViewportWidth);
                    } else {
                        width = textwrapWidth;
                    }

            }

我用于此参考的文档是here以获取更多信息。在没有看到您的代码的情况下,我不确定它到底为什么会发生。那么它显然只是跳过使用这些参数调整任何视图,因此你有你的日志。

[编辑] 在无法显示代码(可以理解)的情况下,除了我之前所说的之外,我唯一可以真正参考的是我不久前在这里阅读的讨论,它揭示了不同上下文包含不同数据的事实。您也许可以使用活动上下文而不是引擎或应用程序上下文。帮助不大,但可能是第一块金砖。:-? 祝你好运,希望你能管理好,我会留意任何参考资料给你。

于 2011-07-04T17:35:21.623 回答
1

我遇到了同样的问题,我的正常 webview 无法正常工作,并给了我与您描述的相同的错误。

skip viewSizeChanged as w is 0

据我了解,这与较新设备允许的 Android 缩放有关,以避免应用程序(专为手机设计)在平板电脑等设备上显示为小窗口应用程序。

我的解决方案:

WebView mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setBuiltInZoomControls(true);

最后一行 setBuiltInZoomControls(true) 让我的问题消失了。我希望这可以帮助你!

[编辑]这个解决方案昨天对我来说很好,但是今天早上我又遇到了错误。这可能不是解决方案。对不起,误导性的帖子。

[EDIT2]现在我已经更改了我的代码,之后我再也没有遇到过错误,我运行了一个包含 1000 次迭代的测试套件而没有出现错误。解决我的问题是 url 没有正确传递给 webview。在确保正确的 url 问题消失后,它得到了一个空字符串。希望这会对某人有所帮助。

于 2011-12-06T15:03:56.903 回答