如何禁用水平滚动Android中的WebView [英] How to disable horizontal scrolling in Android webview

查看:1432
本文介绍了如何禁用水平滚动Android中的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想只有垂直滚动在我的WebView,不希望任何水平滚动。

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

webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);帮我解决了滚动发行

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

但是使用这个使我的WebView看着奇怪。压榨(垂直)的所有编辑文本高度,并期待坏。

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

问题1)是否有任何其他的方式我可以禁用从客户端水平滚动?

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

问题2)使用SINGLE_COLUMN我们如何才能避免问题的​​WebView高度的变化呢?我想垂直的外观和感觉是一样它曾经是没有SINGLE_COLUMN

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

推荐答案

这是一个黑客,而是一个在过去成功地为我工作。环绕你的WebView在垂直方向的滚动型:

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

<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"    >
  <WebView
    android:id="@+id/mywebview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
</ScrollView>

,然后禁用你的WebView所有的滚动。

and then disable all scrolling in your WebView.

要禁用的WebView的滚动,你可以使用这个code:

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);
    }
});

这篇关于如何禁用水平滚动Android中的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆