2011-10-12 78 views
1

放大(通过触摸执行)后,WebView似乎无法正常工作。 要在页面加载缩放页面后再现,但不允许视图在缩放后滚动(这会导致问题不显示)。点击链接。链接突出显示,因为它被点击,但WebView不导航到下一页(如此可见,它保持在同一网址)。 这里是测试项目sourceapk来重现这一点。使用缩放的Android WebView错误

转载Nexus S和HTC wildfire S. 我会感谢您的任何想法或方向。

package com.test; 

import android.app.Activity; 
import android.os.Bundle; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 


public class TestWebViewBugActivity extends Activity { 

    WebView webView; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     webView = (WebView) findViewById(R.id.webView); 
     webView.getSettings().setBuiltInZoomControls(true); 
     webView.getSettings().setSupportZoom(true); 

     webView.setWebViewClient(new WebViewClient() { 
     }); 
     webView.loadUrl("http://google.com/"); 

    } 
} 

P.S. 源和apk中的布局XML根据评论的建议而改变(高度现在是静态值)

回答

0

我相信你需要修复你的Main.xml文件。 WebView中的布局高度是“fill_parent”。当客户端放大时,WebView会影响父母。这是你的Main.XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 
    <WebView 
     android:id="@+id/webView" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
    /> 
</LinearLayout> 

尝试给WebView一个定义的高度。然后尝试缩放客栈,看看会发生什么。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" 
    /> 
    <WebView 
    android:id="@+id/webView" 
    android:layout_width="fill_parent" 
    android:layout_height="500px" 
    /> 
</LinearLayout> 
+0

不幸的是,这并没有帮助。 – Artemm

0

在布局main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
     <WebView 
      android:id="@+id/web_view" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1.0" /> 
</LinearLayout> 

在活动

WebView webView = (WebView) findViewById(R.id.web_view); 
webView.getSettings().setJavaScriptEnabled(true); 
webView.getSettings().setBuiltInZoomControls(true); 
webView.getSettings().setSupportZoom(true); 

webView.loadUrl("http://google.com"); 

,它应该工作。 而不是google.com尝试其他页面。在我的手机上打开默认浏览器。但我的私人工作正常:)

+0

感谢您检查。默认浏览器打开,因为您删除了 webView.setWebViewClient(new WebViewClient(){}); 在默认浏览器中不存在这样的问题。仅在webview中。也玩layout_xxxx没有帮助。 – Artemm

+0

THx提示。它现在工作正常。 还有一件事,你做了什么API应用程序?我创造了我的8(2.2),它适用于我的Galaxy S 2.3.4。也许这是问题? – Versor

+0

它被设置为4(1.6)。切换到2.3并没有帮助。这是不容易重现的东西,除非你知道如何重现它(主要是在放大后不允许视图移动),所以也许你只是没有重现它。 – Artemm