I am developing an application in which I've to use a webview. My question is CAN WE STOP WEBVIEW's BUILT IN SCROLLING FUNCTIONALITY?
I have tried this so for:
in onScrollChanged super.scroll(0,0);
But this wont help me. I'm looking for something like we can stop zooming using the webview settings...
Anyone having better Idea other then this would be great.
Finally I've found the answer myself..:P
we can stop or start scrolling and scaling of the page by doing some javascript stuff in the page. Here is the javascript code:
function stopScroll()
{
document.ontouchmove = function(e){ e.preventDefault(); }
}
function startScroll()
{
document.ontouchmove = function(e){ return true; }
}
Now you can call these functions using your android webview using following:
myWebView.loadUrl("javascript:stopScroll()");
By calling above function stopScroll from the HTML page will be called.
Cheers!!!
WebView WebView1 = (WebView) findViewById(R.id.webView1);
//Only hide the scrollbar, not disables the scrolling:
WebView1.setVerticalScrollBarEnabled(false);
WebView1.setHorizontalScrollBarEnabled(false);
//Only disabled the horizontal scrolling:
WebView1.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
//To disabled the horizontal and vertical scrolling:
webview.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return (event.getAction() == MotionEvent.ACTION_MOVE);
}
});
// details here
I can suggest to look at the problem from another point of view. This helped me when I had the similar issue. I found out that html meta tag "viewport" has great impact on WebView, especially if incorrectly specified. If the web page is developed and maintained by you, then you may use the following meta tag to the of your web pages:
<meta name="viewport" content="width=device-width; user-scalable=0;"/>