How to make AdView quot;occupyquot; space even while requesting an ad? (Android)(如何让 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_width 和 layout_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 “占领"即使在请求广告时也有空间?(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何让 AdView “占领"即使在请求广告时也有空间?(安卓)
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01