我发现:
(1) webview中有两个高度。MeasureHeight 和 contentHeight。请注意,contentHeight 是从 webcoreThread 计算的。两人的身高随时都不一致!
(2) 当布局完成时,webview 重新加载内容。contentHeight 与 measureHeight 一致。
所以我认为一种解决方案是:在布局完成后让 webview 重新加载内容。
我的解决方案:
(1) 扩展 webview 。(2)覆盖onlayout(),dispatchDraw(),</p>
@Override
protected void dispatchDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.dispatchDraw(canvas);
//mchanged == is parameter in onlayout()
//finished == have run the code below !
if (!mchanged && !finished) {
//
String vHtml =".........." ;//your html content
this.loadDataWithBaseURL("目录浏览", vHtml, "text/html", "utf-8", null);
finished = true;
}
}
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
super.onLayout(changed, l, t, r, b);
// tttttt
if (!changed) {
this.mchanged = changed;//false
}
}
(3) webview 在加载每个内容之前需要初始化。
public void intiFlag() {
mchanged = true;
finished = false ;
}
希望这可以帮助。