我有三个并排的 WebView ,用于显示单独的微调器。我有时会收到此错误,这会导致窗口渲染出现问题。
这是我的 xml...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_height="300dp"
android:layout_width="match_parent"
android:gravity="center">
<WebView
android:id="@+id/measure_view"
android:background="#77000000"
android:layout_height="match_parent"
android:layout_width="160dp"
android:focusable="true"/>
<WebView
android:id="@+id/input_view"
android:background="#77000000"
android:layout_height="match_parent"
android:layout_width="160dp"
android:focusable="true"/>
<WebView
android:id="@+id/output_view"
android:background="#77000000"
android:layout_height="match_parent"
android:layout_width="160dp"
android:focusable="true"/>
</LinearLayout>
有什么想法吗?
谢谢,纳撒尼尔。
最佳答案
对于遇到此问题的任何人:
根据我的发现,在创建 webview 时会进行一些线程处理,并且某些变量(例如宽度)正在跨线程引用。这是引用代码“不完美”,因为有时数据在渲染时不可用。
看看这个:
然后按 ctrl-f 错误文本“无法获取 viewWidth”...您就会明白我在说什么。
这里一个有趣的延续是我使用了多个 WebView ——这可能使问题更加复杂。另一个有趣的方面是,在我的代码中失败的 webview 总是第一个将内容加载到其中的,尽管它并不总是失败。
我的解决方案是让事情第一次失败,然后重新渲染失败的 WebView 。
希望这对您有所帮助。
纳撒尼尔。
关于javascript - W/网络核心(2733): Can't get the viewWidth after the first layout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10743051/