WebView未绘制,WARN/webcore(5336):第一个布局后无法获取viewWidth [英] WebView doesn't get drawn, WARN/webcore(5336): Can't get the viewWidth after the first layout
问题描述
我的应用具有一个视图,该视图通过使用以下代码以编程方式添加到活动中:
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);`
按下后退按钮(当然会调用OnDestroy())并再次运行该应用程序后,我看不到视图在屏幕上绘制,并且在DDMS尝试绘制它时收到此警告:
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):在第一个布局后无法获取viewWidth
值得一提的是,该视图在此状态下可以正常工作(根据DDMS上的日志,页面资源正在加载)
It's worth mentioning that the view is functional on this state (the page resources are being loaded, according to the log on DDMS)
同样位于同一ContentView中的其他常规"视图(ImageView,TextView)也可以正常绘制.
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?
推荐答案
尝试使用parent.forceLayout(),然后调用parent.measure().
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.
希望这会有所帮助!
这篇关于WebView未绘制,WARN/webcore(5336):第一个布局后无法获取viewWidth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!