android - 禁用webview中的滚动?

标签 android android-webview android-scroll android-scrollbar

到目前为止,我只是一名 iPhone 开发人员,现在我决定试一试 Android。我在 Android 上无法弄清楚的是如何以编程方式防止在 WebView 中滚动?

类似于 iPhone 防止 onTouchMove 事件的东西会很棒!

最佳答案

这是我在 webview 中禁用所有滚动的代码:

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

仅隐藏滚动条,但不禁用滚动:

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

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

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

您也可以尝试使用垂直滚动的 ScrollView 包装您的 webview 并禁用 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(...) 代码以禁用 webview 中的所有滚动。垂直 ScrollView 将允许滚动 WebView 的内容。

关于android - 禁用webview中的滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2527899/

相关文章:

android - Android 应用程序中 VideoView 中的 RTSP 流

Android webview 出现片刻白色

java - 如何在服务中创建 XWalkView?

android - 如何滚动到 ListActivity 中的子元素

android - 在水平和垂直回收 View 中滚动问题

java - 在 LinearLayout 中定位元素

Android 自定义相机操作返回低分辨率图像

android - ADT:覆盖实际情况的最有效的仿真器设备集?

android - 数据 :text/html not available with certain WebView text/html content strings 处的网页

android - ScrollView 内的 Recyclerview 滚动不顺畅