美文网首页
永久解决Android webview底部空白问题

永久解决Android webview底部空白问题

作者: 李新阳 | 来源:发表于2019-05-22 17:50 被阅读0次

    参考链接

    我改了一点,嵌套布局太多,如果是单一webview就比较好解决

    mBinding.rvContentList.setWebViewClient(new WebViewClient() {

    @Override

      public void onPageFinished(WebView view, String url) {

    mBinding.rvContentList.loadUrl("javascript:App.resize(document.body.getBoundingClientRect().height)");

          super.onPageFinished(view, url);

      }

    });

    mBinding.rvContentList.addJavascriptInterface(this, "App");

    @JavascriptInterface

      public void resize(final float height) {

    Log.e("TAG","promotion"+height);

          getActivity().runOnUiThread(new Runnable() {

    @Override

            public void run() {

    setWebViewHeight(DisplayUtils.dipToPixels(getActivity(), (int)height));

                //Toast.makeText(getActivity(), height + "", Toast.LENGTH_LONG).show();

    //此处的 layoutParmas 需要根据父控件类型进行区分,这里为了简单就不这么做了

    //          mBinding.rvContentList.setLayoutParams(new ConstraintLayout.LayoutParams(getResources().getDisplayMetrics().widthPixels, (int) (height * getResources().getDisplayMetrics().density)));

            }

    });

      }

    private int mWebViewHeight;

      public void setWebViewHeight(final int height) {

    if (height !=mWebViewHeight && height >0) {

    mBinding.rvContentList.getLayoutParams().height = height;

            mBinding.rvContentList.requestLayout();

            mWebViewHeight = height;

          }

    }

    相关文章

      网友评论

          本文标题:永久解决Android webview底部空白问题

          本文链接:https://www.haomeiwen.com/subject/qzanxttx.html