如何优雅的计算webview渲染后的高度

final WebView cotent = (WebView) findViewById(R.id.cotent);
String baseUrl = "file:///android_res/drawable/";//读取本地图片路径
cotent.loadDataWithBaseURL(baseUrl, infoForum.getContent() + "
", "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.csdn.net/linghu_java/article/details/46544811

你可能感兴趣的:(android)