【问题标题】:Android: What does this warning message refer to? - (WebCore)Android:此警告消息指的是什么? - (网络核心)
【发布时间】:2011-07-31 18:01:51
【问题描述】:

我有一个包含 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

提前致谢。

【问题讨论】:

    标签: android android-webview android-gallery


    【解决方案1】:

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

    skip viewSizeChanged as w is 0
    

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

    我的解决方案:

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

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

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

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

    【讨论】:

    • @macbac - 已接受。抱歉回复晚了 :) 有点忙检查。
    • 好吧,如果您的 WebView 的布局高度或宽度与您的父母无关,有时也会导致这种情况。将其设置为匹配父项并检查。
    【解决方案2】:

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

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

    【讨论】:

    • 谢谢,但我已经知道上述参考。我不明白宽度为零的原因。我的意思是我可以在屏幕上看到 WebView。如果我使用 TextView 代替 WebView 则不会出现此警告...至于代码由于法律原因,我不允许发布它。
    • @Fresh_Meat ,我添加了另一个参考供您查看。没有太大帮助,但您是否将其用于广告?如果是这样,你能说出类型吗?公司?等等...?
    猜你喜欢
    • 1970-01-01
    • 2021-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 2017-03-06
    相关资源
    最近更新 更多