Android : Android WebView changes size on configuration change

on Wednesday, March 18, 2015


I have a webview in a fragment in my Android application. I recently specified that my activity should take care of orientation changes by itself and after that I got some problems with my web view.


When orientation changes were automatic, graphs on my web page was reloaded and stretched in width when rotating the device to landscape, which was very much desired. (This is properties of the web site)


This functionality was completely gone when I took care of orientation changes from the activity. So in my web view fragment, I implemented this:



@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
webView.reload();
}


Which does indeed work. When rotating the device to landscape, the webview sends it's new size to the web site and everything looks as it should.


When I rotate the device back to portrait, it changes to the original size (Perfect!) and then, sometimes, once more (NOT PERFECT). Lets say that when rotating it back, it zooms in a bit, and then it zooms once more. So the web content doesn't fit anymore. I haven't found anyone else with this problem, so any help is appreciated.


I have tried getting the width and height for different scenarios (and it's always as expected) and I have checked that to methods are called twice. I have also tried to set minimum width (no difference)...


0 comments:

Post a Comment