1

我对片段中的 WebView 有一个奇怪的问题。水平滚动无法正常工作。它只滚动一点。没有问题,垂直滚动内容,捏合缩放,是的,用两根手指移动页面同时捏合也适用于所有方向。

这是Fragment的onCreateView()-Method,它承载了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>

以及加载片段的布局文件

<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>

因为我使用的是 ABS,所以无法直接在 xml 文件中加载片段。这将引发 ClassCastException。

4

1 回答 1

2

我刚刚搜索了这个并在 SO 上遇到了同样的问题,查看这个答案,看看是否有帮助

他补充说:

mWebView.getSettings().setUseWideViewPort(true);

是的,这似乎ViewPager消耗了您的水平滚动,请查看这两个解决方案。希望他们有所帮助。

于 2012-07-26T00:59:43.007 回答