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 (将#修改为@)