繁体   English   中英

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

[英]Android: Prevent Only Vertical Scrolling in WebView

这是我的代码-

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

但是问题在于它禁用了所有滚动(水平和垂直滚动)。 有什么方法可以禁用垂直滚动并保持水平滚动吗?

您可以使用WebView的内置方法来禁用水平滚动 ,这比操作WebView的OnTouchListener容易

解:

webview.setHorizontalScrollBarEnabled(false);

编辑:

将其包装在水平滚动视图中

 <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