1
我有一個奇怪的問題,一個片段內的WebView。水平滾動無法正常工作。它只滾動一點。垂直滾動內容,捏縮放,是的,用兩根手指移動頁面,同時捏也適用於所有方向。WebView水平滾動失敗
這是onCreateView() - 片段的方法,它攜帶WebView。我無法使用WebViewFragment。 這個片段在Viewpager中!提供的數據是一個有效的html5文檔。但我還沒有成功嘗試過一個「真正的網頁」。
this.mView = inflater.inflate(R.layout.search_results, container, false);
mWebView = (WebView)this.mView.findViewById(R.id.search_results);
mWebView.setWebViewClient(new SearchResultsWebViewClient());
mWebView.setInitialScale(120);
mWebView.setScrollContainer(true);
mWebView.bringToFront();
mWebView.setScrollbarFadingEnabled(true);
mWebView.setVerticalScrollBarEnabled(true);
mWebView.setHorizontalScrollBarEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setJavaScriptEnabled(false);
mWebView.loadData(this.data, "text/html", "utf-8");
return this.mView;
這是search_results.xml
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id ="@+id/search_results"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</WebView>
以及其中由於我使用的是ABS的片段被加載
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false"
android:weightSum="1.0">
<LinearLayout android:layout_weight="0.5"
android:layout_width="0dip"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:drawSelectorOnTop="false"/>
</LinearLayout>
<LinearLayout android:layout_weight="0.5"
android:layout_width="0dip"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout android:id="@+id/resultsWebWiewFragmentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</LinearLayout>
佈局文件,這是不可能的直接在XML文件中加載片段。這會拋出一個ClassCastException。
嘿奧紹克。不,這使情況更糟。我認爲這與ViewPager失敗。尋呼機或WebView正在收集水平滾動。也許我錯了。我發佈了橫向視圖。在縱向上,此WebView作爲單個片段添加到ViewPager。你有沒有試過在WiewPager中水平滾動WebView?這不會工作;)但沒有「分頁」的viewpager沒有意義。 – wog 2012-07-26 12:48:31
對不起,我第一次研究,我沒有包括你使用'viewPager'的事實。請參閱上面編輯我的答案。 – jnthnjns 2012-07-26 13:18:15
嘿,沒問題。其實這些答案正在解決滾動問題。也許我選擇了錯誤的標題。在ViewPager中搜索「WebView」使得這個問題變得不必要;)正如我所說的,從作爲界面設計者的角度來看,根據當前比例或其他狀態在ViewPager中滾動WebView可能沒有多大意義。我想,我要麼將標籤添加到肖像視圖,要麼玩這個美妙的ActionBarSherlock ... – wog 2012-07-26 13:50:46