2012-07-05 63 views
0

我有一個webview和admob的佈局。爲了在設備旋轉時不重新加載頁面內容,我還將方向鍵設置爲主要活動,以便處理onConfigChanges。 當appstarts,創建webview並加載內容時,admob出現,但webview不會自動調整大小!發生時,我將設備轉到橫向並返回肖像,佈局調整大小並正確安裝! 我如何強制webview再次自動調整大小?我嘗試了幾個選項,但沒有成功!謝謝android autosize webview無需重新加載

<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> 
+0

如果您想在代碼中執行此操作,請參閱http://stackoverflow.com/a/33641575/3696999 :) – eJal 2015-11-10 23:28:17

回答

0

試着強制你的adview的高度。 Somethink像

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

哪裏adview_height是存儲在res /值/ dimen.xml的值,例如:

<resources> 
    <dimen name="adview_height">30dp</dimen> 
</resources> 
0

嘗試將視圖與隱藏由默認:

android:visibility="gone" 

並將其設置爲在內容加載時可見:

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