开发者

Webview jittery/jumping

I have a viewflipper that contains a webview. In some cases (seemingly random) the bottom part of the webview will appear to jitter/jump. This can last anywhere between a second and several seconds. Here's a video to illustrate what I'm talking about http://www.youtube.com/watch?v=I8s2P4R95r4

I've now created a basic test project that reproduces the problem http://dl.dropbox.com/u/1256312/WebView%20Test.rar

The problem only occurs in Honeycomb, and usually only in landscape开发者_开发问答 mode. I've tested on several 2.x devices and everything's fine.

After searching I found another case where someone had a similar problem in Honeycomb, but they suggested that the cause was markup related. However the markup I'm using is pretty basic and in any case I've extracted it and made sure that it was valid.

Below is the relevant code. I've removed a lot things from the view to eliminate the problem being elsewhere. View1 has a viewflipper. In the activity I create a number of custom views of type View2 (which contains the offending webview) and add them to the viewflipper.

View1

    <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.

View2

<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>

Loading the webview

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


Try to create and init your web view dynamically. For example in your xml file prepare a container for your web view:

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

Then in the code create, init your web view and also insert web view into container:

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜