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?
Asked
Active
Viewed 8,950 times
7
-
did you found a solution for this :( – A. Albrg Jan 31 '21 at 09:15
2 Answers
14
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);

SoftWyer
- 1,986
- 28
- 33
-
Thanks, problem solved, but i cant accept your solution, button disappeared :( – ZZZ Jul 29 '11 at 05:19
-
1This results in a the scrollbar glitching for me on a HTC Desire S on running 2.3.5. – sleep Apr 19 '12 at 14:09
-
1This solution is not working for me on my Samsung Galaxy S3 running Android 4.1.1. – John Weidner Feb 20 '13 at 00:41
-
1This solution is not working for me on my HTC G20 running Android 4.0.3 – Xianfeng.Cai Apr 17 '13 at 13:29
-
4
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();

dt0
- 713
- 2
- 8
- 18