UPDATED QUESTION: (16th Nov 2016) what in the HTML would make the WebView stop returning valid values for "canScrollXXX"/computeXXXXRange/computeXXXXScrollOffset/computeXXXXScrollExtent and stop the built-in zoom controls displaying.
My Requirement
I have a WebView inside a ViewPager. I would like to have it that the WebView scrolls left and right until it meets the edge of the HTML and then the ViewPager can take over.
My Issue
There are a few questions already on SO about this issue. They all make use of
"computeHorizontalScrollOffset"
but this ALWAYS returns 0 for me.
Furthermore, the following also always returns 0.
final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent();
Does anyone know why the "computeHorizontalScrollOffset" always returns 0?
I have also noticed the built-in zoom controls are not showing, even though i have told them too.
Existing research
The SO questions i have already looked at are the following (among others)
- Scroll webview horizontally inside a ViewPager (Scroll webview horizontally inside a ViewPager)
- How to scroll webview horizontally inside ViewPager (How to scroll webview horizontally inside ViewPager?)
My code
Here is my WebView layout. I have tried a FrameLayout and an LinearLayout and there is no difference.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout >
In my fragment for my ViewPager page, i instantiate the WebView as follows
webView = v.findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDomStorageEnabled(true);
webView.setWebChromeClient(...);
webView.setWebViewClient(...);
UPDATE (16th Nov 2016)
I have actually narrowed this down to be caused by the contents of the WebView.
If i use a different URL in my WebView I see the built-in zoom controls and on moving the view around I see that "canScrollXXX" is now returning true and computeXXXXRange/computeXXXXScrollOffset/computeXXXXScrollExtent appear to all have proper values and the offset even changes depending on where i am in the view. With my desired HTML contents these methods don't return valid values and the built-in zoom controls are never visible.
Therefore I need to be able to determine what in the HTML would make the WebView stop returning valid values for "canScrollXXX"/computeXXXXRange/computeXXXXScrollOffset/computeXXXXScrollExtent and stop the built-in zoom controls displaying.