2014-11-02 75 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