禁用滚动的WebView? [英] Disable scrolling in webview?

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

问题描述

到现在为止我一直是iPhone开发者只,现在我已经决定放弃Android的一个旋转。这是我一直无法找出对Android是如何以编程方式prevent滚动在的WebView

Until now I have been an iPhone developer only and now I have decided to give Android a whirl. Something I haven't been able to figure out on Android is how to programmatically prevent scrolling in a WebView?

也有类似的 onTouchMove 事件的iPhone prevention将是巨大的!

Something similar to iPhones prevention of the onTouchMove event would be great!

推荐答案

下面是我的$ C $下的禁用所有滚动在web视图:

Here is my code for disabling all scrolling in webview:

  // disable scroll on touch
  webview.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
      return (event.getAction() == MotionEvent.ACTION_MOVE);
    }
  });


要只隐藏滚动条,而不是禁用滚动:


To only hide the scrollbars, but not disable scrolling:

WebView.setVerticalScrollBarEnabled(false);
WebView.setHorizontalScrollBarEnabled(false);


或者你可以尝试使用单列布局但这仅适用于简单的页面,并禁用水平滚动:


or you can try using single column layout but this only works with simple pages and it disables horizontal scrolling:

   //Only disabled the horizontal scrolling:
   webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);


您也可以尝试包装你的WebView 与垂直滚动滚动视图和禁用web视图所有滚动:


You can also try to wrap your webview with vertically scrolling scrollview and disable all scrolling on the webview:

<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"
    android:scrollbars="none" />
</ScrollView>

和设置

webview.setScrollContainer(false);

不要忘记添加上述webview.setOnTouchListener(...)code禁用所有滚动的web视图。垂直滚动型将允许滚动的WebView的内容。

Don't forget to add the webview.setOnTouchListener(...) code above to disable all scrolling in the webview. The vertical ScrollView will allow for scrolling of the WebView's content.

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

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