gpt4 book ai didi

android - Webview 抖动/跳跃

转载 作者:太空狗 更新时间:2023-10-29 15:21:38 32 4
gpt4 key购买 nike

我有一个包含 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com