如何解决android webView,为什么高度会像这样循环变化
这是一个简单的案例,其中有一个webView从远程加载一些内容。
当webview布局高度更改时,将强制将html div
之一设置为固定高度。
class LayoutChangeListener() : OnLayoutChangeListener {
override fun onLayoutChange(v: View?,left: Int,top: Int,right: Int,bottom: Int,oldLeft: Int,oldTop: Int,oldRight: Int,oldBottom: Int) {
webview?.let {
val changed = (right - left != oldRight - oldLeft) || (bottom - top != oldBottom - oldTop)
if (changed) {
webview.postDelayed ({
Log.v("+++","+++ onLayoutChange ${webview.measuredHeight}")
updateOneHtmlDivHeight(120)
},10)
}
}
}
}
,但onLayoutChange开始处于循环状态,例如webview.measuredHeight从A-> B-> A-> B-> A.更改,因此onLayoutChange()连续不断地被调用。
它不会一直发生,也不会针对不同的html内容发生,但是很容易进入此循环。
不知道为什么。
有什么想法,或者如何防止它停留在高度变化的循环中?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。