WebView doesn't get drawn, WARN/webcore(5336): Can't get the viewWidth after the first layout

假装没事ソ 提交于 2019-12-07 08:28:51

问题


My app has a view that gets added to activity programmatically using this code:

    RelativeLayout.LayoutParams layoutParams = 
        new RelativeLayout.LayoutParams(480, 75);

    RelativeLayout parent = (RelativeLayout)mMyView.getParent();
    if (parent != null) {
        parent.removeView(mMyView);
    }

    activity.addContentView(mMyView, layoutParams);`

After pressing the Back Button, which ofcourse calls OnDestroy(), and running the app again, I don't see the View get drawn on the screen, and I get this warning on DDMS when it tries to draw it:

WARN/webcore(5336): Can't get the viewWidth after the first layout

It's worth mentioning that the view is functional on this state (the page resources are being loaded, according to the log on DDMS)

Other "regular" views (ImageView, TextView) that are also in the same ContentView are drawing fine.

Any ideas how can I solve this problem, or what can be its source?


回答1:


Try using parent.forceLayout() then call parent.measure().

This forces the layout to redraw itself without any regard for other layout requests (and doesn't redraw the parent views), and then remeasures it with current specs.

Hope this helps!



来源:https://stackoverflow.com/questions/6253337/webview-doesnt-get-drawn-warn-webcore5336-cant-get-the-viewwidth-after-the

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