javascript - W/网络核心(2733): Can't get the viewWidth after the first layout

标签 javascript android html css

我有三个并排的 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 时会进行一些线程处理,并且某些变量(例如宽度)正在跨线程引用。这是引用代码“不完美”,因为有时数据在渲染时不可用。

看看这个:

CODE

然后按 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/

相关文章:

javascript - Google Apps 脚本中 UrlFetchApp.fetch 出现意外错误

javascript - 带有 javascript 的 HTML5 视频 - 多个视频的自定义按钮

c# - 在哪里可以找到我的用户 ID

java - android中不同屏幕尺寸的可绘制尺寸

javascript - 如何使用 Javascript 在 ID 中设置标签样式?

javascript - 如何从客户端将参数添加到 HttpContext.Request.Form 中

Android 房间持久库 - 如何插入具有 List 对象字段的类

android - ORMLite 使用 SQL 插入日期

html - 你如何制作那些新奇的弹出窗口?

javascript - jQuery按钮点击,获取带有class的div