是否可以禁用 android webview 中的所有滚动和缩放?

发布于 2024-12-11 10:35:58 字数 737 浏览 6 评论 0原文

我试图找到答案,但到目前为止还没有成功。

我有一个使用 WebView 的活动。向用户显示的所有内容均以 HTML 和 JavaScript 呈现。也就是说,WebView 占据了它能占据的所有屏幕。 APK 用于存储某些持久数据并启动 WebView

UI 底部有一个基于图标的导航菜单(屏幕底部有 5 个图标),顶部有几个视觉元素(徽标图像和搜索按钮)。顶部元素和底部导航栏之间的所有内容都可以根据用户操作进行更改、刷新或更新。顶部和底部常量之间显示的各种 HTML 布局可以向左、向右、向上和向下滑动。

问题: 当用户点击屏幕右下角最右边的导航图标时,整个 WebView 布局向左移动 5-10 个像素。如果最右边的图标在其左边缘附近被点击,则不会发生这种情况。点击另一个图标会将 WebView 移回到正确的对齐方式。点击最左边的图标不会导致与右边类似的行为。点击屏幕任一边缘附近的活动或非活动 HTML 元素(可以通过滑动移动)不会导致移动行为。

最初,当 WebView 移动时,屏幕右侧的区域被白色填充,我认为这是一个 ScrollBar。我已经完成了我能做的所有 ScrollBar 和缩放禁用操作。现在,当发生偏移时,该区域的背景色(黑色)。

有谁知道如何将 WebView 锁定到位?

I tried to find an answer but have thus far failed.

I have an activity that uses a WebView. Everything that is displayed to the user is rendered in HTML and JavaScript. That is, the WebView takes all the screen it can. The APK is used for storing certain persistent data and launching the WebView.

The UI has an icon based navigation menu at bottom (5 icons across the bottom of the screen), and a couple of visual elements across the top (logo image and search button). Everything in between the top elements and bottom navigation bar can be changed, refreshed or updated depending on user actions. The various HTML layouts that are displayed between the top and bottom constants can be swiped left, right, up and down.

The problem:
When the user taps the right-most navigation icon in the lower right of the screen, the entire WebView layout shifts left 5-10pixels. If the right-most icon is tapped near its left edge, this does not happen. Tapping another icon will shift the WebView back to its correct alignment. Tapping the left-most icon does not cause a similar behavior to the right. Tapping active or inactive HTML elements (that can be moved by swiping) near either edge of the screen does not result in the shifting behavior.

Initially the area on the right of the screen was filled with white when the WebView shifted, and I thought it was a ScrollBar. I have done every bit of ScrollBar and zoom disabling I can. Now the area is the background color (black) when the shift occurs.

Does anyone know a way to lock the durn WebView in place?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想挽留 2024-12-18 10:35:58

是的,您可以通过更改 WebView 的设置来禁用 Webview 中的所有滚动。
这是代码:

WebView myWebView = (WebView) findViewById(R.id.appView); 
myWebView.setVerticalScrollBarEnabled(false);
myWebView.setHorizontalScrollBarEnabled(false);

Yes, you can disable all the scrolling in Webviews by changing the settings of WebView.
Here is the code for that:

WebView myWebView = (WebView) findViewById(R.id.appView); 
myWebView.setVerticalScrollBarEnabled(false);
myWebView.setHorizontalScrollBarEnabled(false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文