WebView onScalechanged Min&最大限度

发布于 2025-01-21 05:46:39 字数 1032 浏览 1 评论 0原文

我已经在项目中实现了一个WebView,需要显示PDF。我启用了捏缩放毫无问题的缩放,也有两个按钮可以控制Zoom in&放大。我需要禁用它们的“缩放”将达到最大值和最小值。

目前,我正在使用canzoomin& canzoomout onscalechanged侦听器中的方法,它有效,但是如果您在AndroidDevelopers官员中阅读,则不会对其进行重新计算。

https:// https://developer.android.com/reference.com/reference/reference/reference/android/android/webkit/, webview#canzoomin()

由于种族条件,这种方法容易出现在 Web渲染和UI线程;更喜欢WebViewClient#onScaLechanged。

我的问题是:我如何知道何时在没有canzoomin&的情况下达到最小值和最大值。 canzoomout

override fun onScaleChanged(view: WebView?, oldScale: Float, newScale: Float) {
    super.onScaleChanged(view, oldScale, newScale)
    bottomBarView.setEnabledItem(view!!.canZoomIn(),ENBottomBarItem.zoomIn)
    bottomBarView.setEnabledItem(view.canZoomOut(),ENBottomBarItem.zoomOut)
}

I have implemented a webview in my project, where I need to show a pdf. I enabled pinch to zoom without any problem, i also have two button to control zoom in & zoom out. I need to disable their if "scaling" will reach maximum and minimum.

At this moment i'm using canZoomIn & canZoomOut method in OnScaleChanged listener and it works but if you read in androidDevelopers official their doesn't reccomend it.

https://developer.android.com/reference/android/webkit/WebView#canZoomIn()

This method is prone to inaccuracy due to race conditions between the
web rendering and UI threads; prefer WebViewClient#onScaleChanged.

My question is: How can i know when user reach min and max without canZoomIn & canZoomOut ?

override fun onScaleChanged(view: WebView?, oldScale: Float, newScale: Float) {
    super.onScaleChanged(view, oldScale, newScale)
    bottomBarView.setEnabledItem(view!!.canZoomIn(),ENBottomBarItem.zoomIn)
    bottomBarView.setEnabledItem(view.canZoomOut(),ENBottomBarItem.zoomOut)
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文