topicWebView.addJavascriptInterface(this, "MyApp"); timer = new Timer(); timerTask = new TimerTask() { @Override public void run() { topicWebView.loadUrl("javascript:MyApp.resize(document.body.getBoundingClientRect().height)"); } };
public void onPageFinished(WebView view, String url) { timer.schedule(timerTask,0,1000); }
@JavascriptInterface public void resize(final float height) { topicWebView.post(new Runnable() { @Override public void run() { Log.e("布局测试","------"); topicWebView.setLayoutParams(new RelativeLayout.LayoutParams(context.getResources().getDisplayMetrics().widthPixels, (int) (height * context.getResources().getDisplayMetrics().density))); } }); }