SK. SK. - 1 year ago 515
Java Question

How to disable horizontal scrolling in Android webview

I want to have only vertical scrolling in my webview and don't want any horizontal scrolling.

webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); helped me to solve the scrolling issue

But using this made my webview looking wierd. Height of all the edit text squeezed (Vertically) and is looking bad.

Q.1) Is there any other way I can disable horizontal scrolling from client side?

Q.2) Using SINGLE_COLUMN how can we avoid issue with webview height changes? I want the vertical look and feel to be same as what it used to be without SINGLE_COLUMN

Answer Source

This is a hack, but one that has worked for me successfully in the past. Surround your WebView in a vertically oriented ScrollView:

android:scrollbars="vertical"    >
    android:layout_height="fill_parent" />

and then disable all scrolling in your WebView.

To disable your WebView's scrolling, you can use this code:

 // disable scroll on touch
webview.setOnTouchListener(new View.OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
      return (event.getAction() == MotionEvent.ACTION_MOVE);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download