在Webview相关代码中添加以下代码:
webview.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); int height = view.getMeasuredHeight(); int width = view.getMeasuredWidth(); view.setLayoutParams(new LinearLayout.LayoutParams(width, height)); } });
这段代码在页面加载完成后进行页面高度和宽度的测量并设置Webview的LayoutParams以保证正确显示。