android - Webview 抖动/跳跃

标签 android android-3.0-honeycomb android-webview viewflipper xoom

我有一个包含 webview 的 viewflipper。在某些情况下(看似随机),webview 的底部会出现抖动/跳跃。这可以持续一秒到几秒之间的任何时间。这是一个视频来说明我在说什么 http://www.youtube.com/watch?v=I8s2P4R95r4

我现在创建了一个重现问题的基本测试项目 http://dl.dropbox.com/u/1256312/WebView%20Test.rar

该问题仅出现在 Honeycomb 中,并且通常仅出现在横向模式下。我已经在多个 2.x 设备上进行了测试,一切正常。

经过搜索我发现了另一个案例,有人在Honeycomb中遇到了类似的问题,但他们认为原因与标记相关。然而,我使用的标记非常基本,无论如何我都提取了它并确保它是有效的。

下面是相关代码。我从 View 中删除了很多东西以消除其他地方的问题。 View1 有一个取景器。在 Activity 中,我创建了一些 View2 类型的自定义 View (其中包含有问题的 webview)并将它们添加到 viewflipper。

View 1

    <LinearLayout android:id="@+id/RelativeLayout01"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:orientation="vertical">


        <ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/question_flipper"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_marginLeft="50dp" 
            android:layout_marginRight="50dp" 
            android:layout_marginTop="50dp">

        </ViewFlipper>  

        <RelativeLayout android:id="@+id/FormulaAndResultLayout"
            android:layout_width="fill_parent"
            android:layout_height="75dp"
.....
etc.

View 2

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/QuestionLinearLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:orientation="vertical" 
    android:background="#123123">
    <WebView android:id="@+id/question_web_view"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/question_figure"
        android:layout_marginTop="5dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:scrollbars="none" 
        android:layout_marginLeft="40dp" 
        android:layout_marginRight="40dp" 
        android:background="#444444"/>

</LinearLayout>

加载 WebView

qWebView = (WebView) view.findViewById(R.id.question_web_view); 
qWebView.loadDataWithBaseURL(null, String.format(questionHTMLHeader,  qObj.questionText), "text/html", "utf-8", null);

最佳答案

尝试动态创建和初始化您的 WebView 。例如,在您的 xml 文件中为您的 Web View 准备一个容器:

<LinearLayout android:id="@+id/container_linear_layout"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical">
</LinearLayout>

然后在代码中创建、初始化您的 WebView 并将 WebView 插入容器:

LinearLayout container = (LinearLayout) this.findViewById(R.id.container_linear_layout);
if(container != null)
{
  WebView descriptionWebView = new WebView(context);
  descriptionWebView.loadDataWithBaseURL(null, someStringHtml, "htm", "utf-8", null);

  int margin = RSUtils.convertDpToPixels(10, context);
  LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT,
  LayoutParams.WRAP_CONTENT);
  layoutParams.setMargins(margin, 0, margin, 0);
  descriptionWebView.setLayoutParams(layoutParams);

  if(descriptionWebView != null)
     container.addView(descriptionWebView);
}

关于android - Webview 抖动/跳跃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7192848/

相关文章:

Android Studio 无法识别 Facebook 导入

android - 空值也插入到 android 中的 mysql 中

Android 3.0 Honeycomb 在解析 RSS feed 时的问题

android - 在 Honeycomb android 3.0 中显示操作栏菜单项的图标

android - 如何在 android webview 中处理 mailto[HTML]

java - 选择动态创建的线性布局 View

java - CardView 每个单独的卡之间不存在间距

ListFragment 中的 Android Actionbar Search 小部件实现

android - 设置/更改更改 Android 中的 WebView 用户代理

java - 在Recyclerview项目Mainactivity中创建url对象,Adapter在默认浏览器中解析加载Url。尝试在 WebView 中?