【Android ScrollView嵌套WebView出现底部空白问题】宝剑锋从磨砺出,梅花香自苦寒来。这篇文章主要讲述Android ScrollView嵌套WebView出现底部空白问题相关的知识,希望能为你提供帮助。
@javascriptInterface
public void resize(final float height) {
WebViewActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
//Toast.makeText(getActivity(), height + "", Toast.LENGTH_LONG).show();
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)mWebView1.getLayoutParams();
layoutParams.width = getResources().getDisplayMetrics().widthPixels;
layoutParams.height = (int) (height * getResources().getDisplayMetrics().density);
mWebView.setLayoutParams(layoutParams);
}
});
}
or
@javascriptInterface
public void resize(final float height) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
//Toast.makeText(getActivity(), height + "", Toast.LENGTH_LONG).show();
mWebView.setLayoutParams(new LinearLayout.LayoutParams(getResources().getDisplayMetrics().widthPixels, (int) (height * getResources().getDisplayMetrics().density)));
}
});
}
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
mWebView.loadUrl("javascript:App.resize(document.body.getBoundingClientRect().height)");
super.onPageFinished(view, url);
}
});
mWebView.addJavascriptInterface(this, "App");
推荐阅读
- Android ListView与RecycleView的对比使用
- applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.
- android WebView音频关闭的问题
- 使用Power BI进行数据可视化
- 充分利用Python和R的优点
- GIT推拉(push和pull)
- Pandas数据准备
- JupyterLab中的SQL接口
- Matplotlib中的直方图