1 2 3 4 5 6 7 8 9
| webview.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { webview.loadUrl("javascript:App.resize(document.getElementById('chatsDataList').scrollHeight)"); super.onPageFinished(view, url); } }); webview.addJavascriptInterface(this, "App"); webview.loadUrl("http://localhost:" + Constant.port + "/pages/indexCharts.html");
|
1 2 3 4 5 6 7 8 9 10 11
| @JavascriptInterface public void resize(final float height) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { TT.showToast(mContext, height + ""); webview.setLayoutParams(new LinearLayout.LayoutParams(getResources().getDisplayMetrics().widthPixels, (int) (height * getResources().getDisplayMetrics().density))); } }); }
|
注意:
chatsDataList
要修改成自己的元素
- 要运行在UI线程
- 要设置LayoutParams
webView.getLayoutParams().height =height;是没有用的