William Lewis William Lewis - 11 months ago 60
HTML Question

WebView Orientation Change not resizing Webpage

I'm making an android app and if I am at the very top of my WebView and I try to switch my phone into landscape mode, then it wont resize the webpage to fit my phones screen. It will only take up half of the screen, but then if I scroll down a little bit and switch to landscape mode it works fine!

I have

in the Android Manifest to keep the webview from resetting when i do change the orientation.


Even if you are a tenth of a inch from the top of the page it will work fine, but if you are all the way at the top of the page it won't work.

This is the class im having problems with:

package my.app.name;

import my.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class ConverterCatalogActivity extends Activity {
WebView browser;
public void onCreate(Bundle savedInstanceState) {

/* Set the Content View */

/* Get the WebView */
WebView wv1 = (WebView) findViewById(R.id.wv1);

/* Activate JavaScript */

/* Prevent WebView from Opening the Browser */
wv1.setWebViewClient(new InsideWebViewClient());

public void onConfigurationChanged(Configuration newConfig) {
// We do nothing here. We're only handling this to keep orientation
// or keyboard hiding from causing the WebView activity to restart.

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK){
return true;

return super.onKeyDown(keyCode, event);

/* Class that prevents opening the Browser */
private class InsideWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;

Here's a screenshot of it in landscape mode.


I've had issues with WebViews doing this before. Try measuring the view in OnOrientationChanged and it may fix your problem!