webView加载后计算网页高度、若有误可以让网页加接口传高度(测试本地网页高度需要计算,http远程网页不需要以下逻辑加载正常)
setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
final int measuredHeight = getMeasureContentHeight();
//主线程更新UI
post(new Runnable() {
@Override
public void run() {
ViewGroup.LayoutParams params = getLayoutParams();
params.height = measuredHeight;
setLayoutParams(params);
}
});
Log.d("CustomWebView", "measuredHeight:" + measuredHeight + ",getContentHeight" + getContentHeight() + ",getHeight" + getHeight() + ",getMeasureContentHeight" + getMeasuredHeight());
super.onPageFinished(view, url);
}
});
网友评论