HTC One X - 触摸后Webview变为白色/空白

时间:2012-06-21 08:36:10

标签: android webview htc-android

我有一个Android应用程序,它有搜索文本框,一些按钮,webviews(1个可见2个不可见)和一个admob adview。该应用程序只搜索一些特殊网站,它在模拟器,三星galaxy设备上运行良好。但我对HTC One X有疑问(不了解其他HTC型号)。

问题是,当您单击搜索按钮时,webview会加载页面。然后“有时”当你试图触摸甚至滚动时,webview只返回带有滚动条的全白区域。特别是在广告刷新后,会发生这甚至有时候广告的背景和文字区域也会变成白色 - 也是不可读的。在广告上只有蓝色箭头和蓝色电话图像保持可见!

有没有人有这样的问题,还有任何解决方案吗?提前谢谢。

这是我的布局xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/layoutDashboard"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:background="@drawable/border_shape"
            android:orientation="vertical"
            android:paddingTop="1sp" >

            <EditText
                android:id="@+id/editxtKeyword"
                android:layout_width="fill_parent"
                android:layout_height="43dp"
                android:layout_marginLeft="1dp"
                android:layout_marginRight="1dp"
                android:layout_marginTop="2dp"
                android:ems="10"
                android:hint="@string/editxtKeyword_hint"
                android:singleLine="true" >
            </EditText>

            <HorizontalScrollView
                android:id="@+id/horizontalScrollView1"
                android:layout_width="fill_parent"
                android:layout_height="0dip"
                android:layout_gravity="center_vertical"
                android:layout_weight="0.30"
                android:paddingBottom="2dp"
                android:paddingLeft="1dp"
                android:scrollbars="none" >

                <LinearLayout
                    android:id="@+id/layoutButtons"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_gravity="center_vertical"
                    android:layout_marginTop="0dp"
                    android:layout_marginBottom="1dp"
                    android:layout_marginLeft="1dp"
                    android:layout_marginRight="1dp"
                    android:orientation="horizontal" >
<
                    <Button
                        android:id="@+id/btnAk"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_margin="1dp"
                        android:background="@drawable/custom_button_shape"
                        android:text="asd" />

                    <Button
                        android:id="@+id/btnCm"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_margin="1dp"
                        android:background="@drawable/custom_button_shape"
                        android:text="csm" />

                </LinearLayout>
            </HorizontalScrollView>
        </LinearLayout>

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <WebView
                android:id="@+id/webV"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_above="@+id/linlaylay1"
                android:visibility="visible" />

            <WebView
                android:id="@+id/webVAnalytics"
                android:layout_width="1dp"
                android:layout_height="0dp"
                android:visibility="invisible" />

            <WebView
                android:id="@+id/WebVSahibinden"
                android:layout_width="1dp"
                android:layout_height="0dp"
                android:visibility="invisible" />

            <LinearLayout
                android:id="@+id/linlaylay1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_margin="0dp"
                android:orientation="vertical"
                android:padding="0dp" >

                <com.google.ads.AdView
                    android:id="@+id/adViewSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal|top"
                    ads:adSize="BANNER"
                    ads:adUnitId="a123123"
                    ads:loadAdOnCreate="true"
                    ads:testDevices="TEST_EMULATOR"  />
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/layoutProgress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|center_horizontal"
        android:layout_marginBottom="50dp"
        android:layout_marginTop="5dp"
        android:background="@drawable/progress_shape"
        android:padding="2dp"
        android:visibility="invisible" >

        <TextView
            android:id="@+id/lblLoading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            android:text="@string/msg_loading"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000000" />

        <ImageButton
            android:contentDescription="@string/dialog_cancel"
            android:id="@+id/btnStop"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:src="@drawable/stop" />
    </LinearLayout>

</FrameLayout>

3 个答案:

答案 0 :(得分:2)

将硬件加速视图相互显示时存在许多问题。我会重新设计你的布局,不要重叠网页视图或滚动视图,或禁用硬件加速。

答案 1 :(得分:2)

A known bug

您可以在WebView上禁用硬件加速,但请确保以不破坏旧设备的方式执行此操作:

if(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.HONEYCOMB){
    //mWebView is some WebView
    mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

<强>注意事项

  • 视频无法在浏览器中播放
  • 滚动不会那么顺利

这是根据bug修复了Jelly Bean但我无法亲自验证。

答案 2 :(得分:1)

我在HTC手机上看到过单一网页浏览的问题。 One of the comments in this bug thread提供了一些有助于优化WebView性能的建议。这个错误是关于3D转换的,但我发现注释的技术对于WebViews一般都很有用。

This presentation at Google I/O 2012也提供了一些关于WebViews主题的好信息。

两者都建议将动态内容放在“图层”上。这意味着将此CSS规则分配给元素:

  -webkit-transform: translate3d(0, 0, 0);

通过应用此规则,Android“告诉浏览器将图层预先合成到自己的纹理上,以便稍后可以动画(几乎)免费”这种行为不是免费的 - 它可以消耗更多内存,所以我会申请明智的。上面链接的演示文稿很好地解释了原因。

就我而言,我可以通过将此规则应用于包装整个页面的DIV来避免“白屏”。该页面有时会呈现白色一秒钟,然后呈现内容。我没有看到“白色”页面永远存在,就像我在应用此技术之前所做的那样。我没有看到失控的内存消耗。 YMMV。

我还建议您尽可能简化布局。说起来容易做起来难,但可以找到一些好的建议in the docs