gpt4 book ai didi

android - 禁用webview中的滚动?

转载 作者:IT老高 更新时间:2023-10-28 13:09:23 27 4
gpt4 key购买 nike

到目前为止,我只是一名 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com