W / webcore(2733):在第一个布局后无法获取viewWidth

时间:2012-05-24 18:12:52

标签: javascript android html css

我有三个网络视图彼此相邻,用于显示单独的微调器。我有时会收到此错误,这会导致窗口渲染出现问题。

继承人我的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>

有什么想法吗?

谢谢,纳撒尼尔。

2 个答案:

答案 0 :(得分:1)

对于遇到此问题的任何人:

从我发现创建webview时会发生一些线程,并且某些变量(例如,width)正在跨线程引用。这是引用代码“不完美”,因为有时数据在渲染时不可用。

看看这个:

CODE

和ctrl-f错误文本“无法获取viewWidth”......你会看到我在说什么。

这里有一个有趣的延续是我使用了多个网页浏览 - 这可能会加剧这个问题。另一个有趣的方面是我的代码中失败的webview始终是第一个将内容加载到其中的内容,尽管它并不总是失败。

我的解决方案是让第一次失败,然后重新渲染失败的Web视图。

希望这有帮助。

纳撒尼尔。

答案 1 :(得分:0)

无法加载时会发生什么?你在logcat中得到错误吗?

加载数据后,尝试这样做:

webView.refreshDrawableState();