美文网首页
Android 测量WebView内容的高度 适用(4.4)Sc

Android 测量WebView内容的高度 适用(4.4)Sc

作者: 146ec3176f2f | 来源:发表于2017-12-26 12:20 被阅读0次

android:layout_width="match_parent"

android:layout_height="match_parent"

>

android:id="@+id/rootView"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

private void measureContent(finalString message) {

LinearLayout.LayoutParams params =newLinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,

ViewGroup.LayoutParams.WRAP_CONTENT);

finalWebView webView =newWebView(this);

mRootView.addView(webView,params);

webView.loadDataWithBaseURL(null,message,"text/html","utf-8", null);

webView.setWebViewClient(newWebViewClient() {

@Override

public voidonPageFinished(finalWebView view,String url) {

newHandler().postDelayed(newRunnable() {

public voidrun() {

Toast.makeText(MainActivity.this,webView.getMeasuredHeight()+"==="+webView.getHeight(),Toast.LENGTH_SHORT).show();

}

},200);//时间很关键

super.onPageFinished(view,url);

}

});

}

相关文章

网友评论

      本文标题:Android 测量WebView内容的高度 适用(4.4)Sc

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