开发者

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

开发者 https://www.devze.com 2023-03-10 23:21 出处:网络
My app has a view that gets added to activity programmatically using this code: RelativeLayout.LayoutParams layoutParams =

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?


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号