2011-10-12 49 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