0

I have a layout with a webview and admob. I also set orientation|keyboard to main activity in order handle onConfigChanges in order to not reload page content when device rotation. When appstarts, webview is created and content loaded, then, admob appears but webview is not auto resized! When happens, I turn device to landscape and return to portrait, layout is resized and properly fitted! How could I force webview to auto resize again? I tried several options but no succes! thank you

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">


      <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="xxx"
                         ads:adSize="SMART_BANNER"
                         ads:testDevices="TEST_EMULATOR, xxx"
                         ads:loadAdOnCreate="true"/>    

<RelativeLayout
                    android:id="@+id/bLayout"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_below="@+id/barraSocial">

                    <WebView
                        android:id="@+id/webviewB"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:autoLink="web"
                        android:textColor="@android:color/black" 
                        android:scrollbars="none"
                        />
                </RelativeLayout>
Jaume
  • 3,672
  • 19
  • 60
  • 119
  • if you want to do it in your code, just see http://stackoverflow.com/a/33641575/3696999 :) – eJal Nov 10 '15 at 23:28

2 Answers2

0

Try to force the height of your adview. Somethink like that

<com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="@dimen/adview_height" />

Where adview_height is the value stored in res/values/dimen.xml, for example:

<resources>
    <dimen name="adview_height">30dp</dimen>
</resources>
Stefano Ortisi
  • 5,288
  • 3
  • 33
  • 41
0

Try setting the view as hidden by default with :

android:visibility="gone"

and set it to visible when the content is loaded :

        webView.loadUrl(url);
        webView.setWebViewClient(new WebViewClient() {
            public void onPageFinished(WebView view, String url) {
                webView.setVisibility(View.VISIBLE);
                super.onPageFinished(view, url);
            }
        });
totteire
  • 97
  • 1
  • 4