Any way to stop WebView built in scrolling

2019-02-26 21:26发布

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.

3条回答
Explosion°爆炸
2楼-- · 2019-02-26 21:47
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

查看更多
贼婆χ
3楼-- · 2019-02-26 22:04

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

查看更多
劫难
4楼-- · 2019-02-26 22:08

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;"/>
查看更多
登录 后发表回答