I want to have only vertical scrolling in my webview and don't want any horizontal scrolling.
webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
This 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.
Is there any other way I can disable horizontal scrolling from client side?
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
Basically intercept the touch event and don't allow the x value to change. This allows the webview to scroll vertically but not horizontally. Do it for y if you want the opposite. But It disabled clicking action in the Webview.
setScrollContainer(false); Don't forget to add the webview. setOnTouchListener(...) code above to disable all scrolling in the webview.
To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML. CSS.
Putting android:scrollbars="none" on the HorizontalScrollView element has no effect. as mentioned by @Benito, do it programmatically.
Here is how I disable horizontal scrolling only for a webview.
webView.setHorizontalScrollBarEnabled(false);
webView.setOnTouchListener(new View.OnTouchListener() {
float m_downX;
public boolean onTouch(View v, MotionEvent event) {
if (event.getPointerCount() > 1) {
//Multi touch detected
return true;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
// save the x
m_downX = event.getX();
break;
}
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP: {
// set x so that it doesn't move
event.setLocation(m_downX, event.getY());
break;
}
}
return false;
}
});
Basically intercept the touch event and don't allow the x value to change. This allows the webview to scroll vertically but not horizontally. Do it for y if you want the opposite.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With