如何让 AdView “占领"即使在请求广告时也有空间?(安卓) [英] How to make AdView "occupy" space even while requesting an ad? (Android)

查看:25
本文介绍了如何让 AdView “占领"即使在请求广告时也有空间?(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用适用于 Android 的 Google AdMob Ads SDK 4.0.4

I'm using Google AdMob Ads SDK 4.0.4 for Android

默认情况下,在广告加载之前,AdView 没有大小.如果您在广告上方或下方有按钮,这可能会导致问题.

By default, The AdView will have no size until the ad is loaded. Which could cause problem if you have buttons above or below the ad.

如果广告在他们即将点击按钮的确切时刻返回,用户可能会意外点击广告.

User could accidentally click on the ad if the ad returned at the exact moment they are about to click a button.

在旧的 admob SDK 中,我使用 setGoneWithoutAd(false) 解决了这个问题.这样,即使广告尚未归还,也会保留空间.

In old admob SDK I solved this by using setGoneWithoutAd(false). This way, the space will be preserved even when the ad is not returned yet.

在新的 SDK (Google Admob Ads SDK 4.0.4) 中,我设法通过使用这个快速修复:通过将广告放置在某些布局中来保留空间有 width="320dp" 和 height="50dp"

In the new SDK (Google Admob Ads SDK 4.0.4) I manage to do the same by using this quick fix: reserve the space by putting ad in some layout that has width="320dp" and height="50dp"

<LinearLayout 
                        android:layout_width="320dp" 
                        android:layout_height="50dp" > 
                  <com.google.ads.AdView android:id="@+id/adview" 
                         android:layout_width="wrap_content" 
                         android:layout_height="wrap_content" 
                         ads:adUnitId="xxxxxxxxxxx" 
                         ads:adSize="BANNER"/> 
</LinearLayout> 

它有效,但我不确定这是否是正确的方法.(我会遇到著名的没有足够的空间来展示广告!"问题吗?)

It works but I'm not sure if this is a proper method.(Will I run into the famous "Not enough space to show ad!" issue? )

总结问题:即使在请求广告时,如何(正确地)让 AdView占用"空间?

To sum up the question: How to(properly) make AdView "occupy" space even while requesting an ad?

提前感谢您!

推荐答案

首先你必须决定你想要的广告尺寸.有几个预定义的.

First you have to decide the ad size that you want. There are a couple of pre-defined ones.

最容易使用的是SMART_BANNER,它会调整它的宽度以匹配当前的屏幕宽度,对于屏幕高度 <=400、(>400 && <=720) 或 >720 dp,它的高度分别为 32、50 或 90 dp.

The easiest to work with is SMART_BANNER, it will adapt it's width to match the current screen width, and it's height will be 32, 50 or 90 dp for screen heights <=400, (>400 && <=720) or >720 dp respectively.

一旦您知道要请求的横幅类型,您就可以在 adSize 属性中声明它,并使用 layout_widthlayout_height 属性.

Once you know the type of banner you will request, you declare it on adSize property and reserve the space for this using layout_width and layout_height properties.

例如,对于 SMART_BANNER,您可以执行以下操作:

For example for an SMART_BANNER you can do something like this:

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="@dimen/ad_banner_height"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="xxxxxxxxx"/>

您会将 ad_banner_height 设置为以下值:

And you will set ad_banner_height to the following values:

values/dimens/ad_banner_height --> 32dp
values-h400dp/dimens/ad_banner_height --> 50dp
values-h720dp/dimens/ad_banner_height --> 90dp

对于其他横幅尺寸,请查看:https://developers.google.com/admob/android/banner#banner_sizes

For other banner sizes, check: https://developers.google.com/admob/android/banner#banner_sizes

这篇关于如何让 AdView “占领"即使在请求广告时也有空间?(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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