gpt4 book ai didi

android - WebView 未绘制,WARN/webcore(5336) : Can't get the viewWidth after the first layout

转载 作者:太空宇宙 更新时间:2023-11-03 10:30:36 25 4
gpt4 key购买 nike

我的应用有一个 View ,该 View 使用以下代码以编程方式添加到 Activity 中:

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

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

activity.addContentView(mMyView, layoutParams);`

按下后退按钮(当然会调用 OnDestroy())并再次运行应用程序后,我没有在屏幕上看到 View 被绘制,并且当 DDMS 尝试绘制它时我收到此警告:

WARN/webcore(5336): 第一次布局后无法获取viewWidth

值得一提的是, View 在此状态下起作用(根据 DDMS 上的日志,正在加载页面资源)

同样位于同一 ContentView 中的其他“常规” View (ImageView、TextView)绘制正常。

有什么办法可以解决这个问题,或者它的根源是什么?

最佳答案

尝试使用 parent.forceLayout() 然后调用 parent.measure()。

这会强制布局自行重绘而不考虑其他布局请求(并且不会重绘父 View ),然后使用当前规范重新测量它。

希望这对您有所帮助!

关于android - WebView 未绘制,WARN/webcore(5336) : Can't get the viewWidth after the first layout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6253337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com