Smart banner container view won't resize

别等时光非礼了梦想. 提交于 2019-12-13 01:29:14

问题


Given the following layout for a content view of a main activity

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

I can't make AdMob's smart banners to work upon orientation change.

If I start in landscape mode, I get a smart banner of height 32. Changing orientation to portrait doesn't change layout_ad height and I get this error

Not enough space to show ad. Needs 480x32 dp, but only has 320x455 dp.


回答1:


The AdView needs to be recreated if you're using SMART_BANNER and handling your own configuration changes. Otherwise, the AdView size doesn't get changed, but the request is still for a full width ad in the new orientation, and so it doesn't fit. Recreating the AdView in this case may be easier for you to do in code than via XML.



来源:https://stackoverflow.com/questions/26703152/smart-banner-container-view-wont-resize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!