禁用滚动的WebView?WebView

由网友(撕心裂肺)分享简介:到现在为止我一直是iPhone开发者只,现在我已经决定放弃Android的一个旋转。这是我一直无法找出对Android是如何以编程方式prevent滚动在的WebView ?Until now I have been an iPhone developer only and now I have decided to...

到现在为止我一直是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);

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

Win10专业版禁用非活动窗口滚动方法

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.

阅读全文

相关推荐

最新文章