WebView not drawn, WARN / webcore (5336): cannot get viewWidth after first layout

My application has a view that is programmatically added to the activity 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 clicking the "Back" button, which, in turn, calls OnDestroy () and starts the application again, I don’t see the View drawing on the screen, and I get this warning in DDMS when it tries to draw it:

WARN / webcore (5336): cannot get viewWidth after first layout

It should be noted that the presentation operates in this state (page resources are loaded in accordance with the DDMS protocol)

Other "normal" views (ImageView, TextView), which are also in the same ContentView, are beautifully drawn.

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

+4
source share
1 answer

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

This forces the layout to redraw itself, not paying attention to other layout requests (and does not redraw the parent views), and then reevaluates it with the current specifications.

Hope this helps!

+2
source

All Articles