wog
wog

Reputation: 135

WebView horizontal scrolling fails

I've got a strange issue with a WebView inside a fragment. The horizontal scrolling doesn't work properly. It scrolls only a bit. It's no problem, to scroll the content vertically, pinch to zoom, and yes, moving the page with two fingers while pinching also works in all directions.

This is the onCreateView()-Method of the Fragment, that carries the WebView. I can't use WebViewFragment. This Fragment is inside a Viewpager! The provided data is a valid html5 document. But I've not successfully tried a "real webpage" as well.

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;

This is the 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>

And the layout-file in which the fragment is loaded

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

Because I'm using ABS, it isn't possible to load the fragment directly in the xml file. This'll throw a ClassCastException.

Upvotes: 1

Views: 8124

Answers (1)

jnthnjns
jnthnjns

Reputation: 8925

I just searched this and ran into the same question on SO, check out this answer and see if that helps.

He added the following:

mWebView.getSettings().setUseWideViewPort(true);

Yeah It seems like the ViewPager consumes your horizontal scroll, check out these two solutions. Hopefully they help.

Upvotes: 2

Related Questions