zoukankan      html  css  js  c++  java
  • 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");
  • 相关阅读:
    cppPrimer学习18th
    cppPrimer学习17th
    cppPrimer学习15th
    常用网站记录
    cppPrimer学习16th
    关于nfs内网穿透frp/nps的问题记录
    unp[unix 网络环境编程]学习 vscode环境搭建
    cppPrimer学习14th
    cppPrimer学习14th
    cppPrimer学习13th
  • 原文地址:https://www.cnblogs.com/xueqiang911226/p/8046277.html
Copyright © 2011-2022 走看看