final WebView cotent = (WebView) findViewById(R.id.cotent);
String baseUrl = "file:///android_res/drawable/";//读取本地图片路径
cotent.loadDataWithBaseURL(baseUrl, infoForum.getContent() + "</br> <img src=\"/android_res/drawable/d_aini.png\"/> ", "text/html", "utf-8", null);
cotent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
System.out.println("cotent.getHeight()===" + cotent.getHeight());//返回的是View的高度
System.out.println("cotent.getContentHeight()===" + cotent.getContentHeight());//返回的是Html的高度
System.out.println("cotent.getMeasuredHeight()===" + cotent.getMeasuredHeight());//返回的是View的高度
}
});
学习网址:http://blog.youkuaiyun.com/linghu_java/article/details/46544811
如何优雅的计算webview渲染后的高度
最新推荐文章于 2021-12-25 12:28:05 发布