设置AdMob的横幅通过XML来匹配父宽度 [英] Set AdMob banner to match parent width by XML

查看:254
本文介绍了设置AdMob的横幅通过XML来匹配父宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置AdMob的横幅广告来匹配它的父的宽度。

I'm trying to set AdMob banner ad to match it's parent width.

我想作为样本:

<com.google.ads.AdView
        android:id="@+id/ad"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center"
        ads:adSize="BANNER"
        ads:adUnitId="app-pub-id"
        ads:loadAdOnCreate="true"/>

和有:

我也试过有:

ads:adSize="SMART_BANNER"

在IDE中的XML preVIEW,我得到了:

In the IDE xml preview, I got:

但事实上,广告不符合他的父母宽度。

But in fact the ad didn't match his parent width.

有人吗?

推荐答案

正确的方法来设置AdMob的横幅用XML来匹配他的父母是:

The right way to set AdMob banner to match his parent by XML is:

<com.google.ads.AdView
        android:id="@+id/ad"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="ca-app-pub_id"
        ads:loadAdOnCreate="true"/>

在另外,作为提前,以匹配父的能力取决于广告商

In addition, as mention before, the ability to match parent depends on the advertiser.

如果广告客户提供相关的资源,该广告将延伸,以符合他的父母。

If the advertiser supplied the relevant resources, the ad will stretch to match his parent.

有关的Nexus 4例如全尺寸的广告:

For example full size ad on Nexus 4:

这篇关于设置AdMob的横幅通过XML来匹配父宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆