How a change the content size of a webview in android?

亡梦爱人 提交于 2019-12-30 18:25:41

问题


I have a webview control in a scrollview. when i load a long html document into it, it resizes to accommodate it. this is correct. however, when i use the same control again afterwards and put less space-consuming html into it, the content size doesn't shrink. this is a problem because the user is able to still scroll a short document into white space. any ideas on how to resolve this?


回答1:


I had a similar problem and resolved it by clearing the view and re-measuring with a small size prior to loading the view again.

e.g.

  webView.clearView();
  webView.measure(10, 10);



回答2:


This didn't work for me when using:

loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl)

But calling requestLayout() on the webview after loading the data worked except for a strange glitch with the scrollbar flickering if changing the view while scrolling.

webView.clearView();
webView.loadDataWithBaseURL(null, data, "text/html", "utf-8", null);
webView.requestLayout();


来源:https://stackoverflow.com/questions/4440640/how-a-change-the-content-size-of-a-webview-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!