Until now I have been an iPhone developer only and now I have decided to give Android a whirl. Something I haven't been able to figure out on Android is how to programmatically prevent scrolling in a WebView
?
Something similar to iPhones prevention of the onTouchMove
event would be great!
I haven't tried this as I have yet to encounter this problem, but perhaps you could overrive the onScroll function?
To Disbale scroll use this
webView.setOnTouchListener(new View.OnTouchListener() {
Here is my code for disabling all scrolling in webview:
To only hide the scrollbars, but not disable scrolling:
or you can try using single column layout but this only works with simple pages and it disables horizontal scrolling:
You can also try to wrap your webview with vertically scrolling scrollview and disable all scrolling on the webview:
And set
Don't forget to add the
webview.setOnTouchListener(...)
code above to disable all scrolling in the webview. The vertical ScrollView will allow for scrolling of the WebView's content.This should be the complete answer. As suggested by @GDanger . Extend WebView to override the scroll methods and embed the custom webview within layout xml.
And then embed in layout file as follows
Then in the Activity, use some additional methods for disabling scrollbars too.
// Disable all scrolling
// Disable horizontal scroll only
// Disable vertical scroll only
In my case threshold value was 20
Adding the margin details to the body will prevent scrolling if your content properly wraps, as so:
Easy enough, and a lot less code + bug overhead :)