智能横幅容器视图不会调整大小

时间:2014-11-02 19:03:30

标签: android layout admob

给出主要活动的内容视图的以下布局

<?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。

1 个答案:

答案 0 :(得分:3)

如果您正在使用SMART_BANNER并处理自己的配置更改,则需要重新创建AdView。否则,AdView尺寸不会更改,但请求仍然是新方向的全宽广告,因此不适合。在这种情况下重新创建AdView可能比使用XML更容易在代码中完成。