简体   繁体   English

Android:仅防止在WebView中垂直滚动

[英]Android: Prevent Only Vertical Scrolling in WebView

Here is my code - 这是我的代码-

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

But the problem is that it disables all scrolling (horizontal and vertical too). 但是问题在于它禁用了所有滚动(水平和垂直滚动)。 Is there any way to just disable vertical scrolling and keep horizontal scrolling? 有什么方法可以禁用垂直滚动并保持水平滚动吗?

You can use the build in method of the WebView for disabling the horizontal scroll which is easy than manipulating the OnTouchListener of the WebView 您可以使用WebView的内置方法来禁用水平滚动 ,这比操作WebView的OnTouchListener容易

solution: 解:

webview.setHorizontalScrollBarEnabled(false);

EDIT: 编辑:

wrap it in horizontal scrollview 将其包装在水平滚动视图中

 <HorizontalScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
         >

        <WebView
            android:id="@+id/mywebview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </HorizontalScrollView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM