2014-11-02 70 views
1

考慮下面的佈局主要活動智能旗幟容器視圖不會調整

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".CordovaApp" 
    tools:ignore="MergeRootFrame" > 

    <LinearLayout 
     android:id="@+id/layout_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:layout_above="@+id/layout_ad" > 
    </LinearLayout> 

    <RelativeLayout 
     android:id="@+id/layout_ad" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="vertical" > 

     <com.google.android.gms.ads.AdView 
      android:id="@+id/view_ad" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      ads:adSize="SMART_BANNER" 
      ads:adUnitId="ca-app-pub-3940256099942544/6300978111" > 
     </com.google.android.gms.ads.AdView> 
    </RelativeLayout> 

</RelativeLayout> 

我不能讓AdMob的智能橫幅在方向變化工作的內容視圖。

如果我在橫向模式下啓動時,我得到高度32.修改方向爲縱向不改變layout_ad高度的智能旗幟,我得到這個錯誤

沒有足夠的空間來顯示廣告。需要480x32 DP,但只有320x455 DP。

+0

它抱怨的是寬度而不是高度。 – William 2014-11-03 21:38:29

+0

http://stackoverflow.com/questions/20929963/admob-ad-not-resizing-correctly-upon-screen-orientation-includes-pictures和http://stackoverflow.com/questions/11281562/android- admob-resize-on-landscape – 2015-04-08 14:35:47

回答

3

如果您使用SMART_BANNER並處理您自己的配置更改,則需要重新創建AdView。否則,AdView大小不會更改,但該請求仍適用於新定位中的全寬廣告,因此不適合。在這種情況下重新創建AdView可能比通過XML更容易在代碼中執行。

+1

http://stackoverflow.com/a/29516024/1816603中的示例代碼 – 2015-04-08 14:34:46