如何让AdView“占领”即使在请求广告时也有空间吗? (安卓)
我正在使用适用于 Android 的 Google AdMob Ads SDK 4.0.4
默认情况下,AdView 在广告加载之前没有任何大小。如果广告上方或下方有按钮,这可能会导致问题。
如果广告在用户即将点击按钮时返回,则用户可能会意外点击广告。
在旧的 admob SDK 中,我通过使用 setGoneWithoutAd(false) 解决了这个问题。这样,即使广告尚未返回,也会保留空间。
在新的 SDK(Google Admob Ads SDK 4.0.4)中,我设法通过以下方式执行相同的操作 使用此快速修复:通过将广告放入某些布局中来保留空间 有 width="320dp" 和 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>
它可以工作,但我不确定这是否是一个正确的方法。(我会遇到著名的“没有足够的空间来显示广告!”问题吗?)
总结一下问题:即使在请求广告时,如何(正确地)使 AdView“占据”空间?
先感谢您!
I'm using Google AdMob Ads SDK 4.0.4 for Android
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.
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.
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? )
To sum up the question: How to(properly) make AdView "occupy" space even while requesting an ad?
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,您必须决定所需的广告尺寸。有几个预定义的。
最容易使用的是SMART_BANNER,它会调整其宽度以匹配当前的屏幕宽度,
对于屏幕高度 <= 400、(> 400 & & <= 720) 或 > 720 dp,其高度分别为 32、50 或 90 dp。
一旦您知道了您要请求的横幅类型,您就可以在 adSize 属性中声明它,并使用 layout_width< /strong> 和 layout_height 属性。
例如,对于 SMART_BANNER,您可以执行以下操作:
您可以将 ad_banner_height 设置为以下值:
对于其他横幅尺寸,请检查:https://developers.google.com/admob/android/banner#banner_sizes
First you have to decide the ad size that you want. There are a couple of pre-defined ones.
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.
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.
For example for an SMART_BANNER you can do something like this:
And you will set ad_banner_height to the following values:
For other banner sizes, check: https://developers.google.com/admob/android/banner#banner_sizes
您尝试过吗:
我使用 AdWhirl 为我提供广告,我的方式是使用与固定尺寸类似的固定视图。看起来您已将其设置为包装内容,使视图在没有任何内容时消失。尝试一下并让我知道效果如何。
Have you tried:
I use AdWhirl to serve my ads for me and the way I have it is with a fixed view similar to this with fixed dimensions. Looks like you have it set to wrap content making the view disappear when nothing's there. Try it out and let me know how it works out.
在我的横幅设计中:
如果不是高级模式,我
首先调用此方法,我显示在设计中分配的占据60dp的横幅,我添加了一个侦听器,以便在横幅无法加载时隐藏空间,但如果横幅已加载它分配高度和宽度 WRAP_CONTENT 并显示它
In my Banner design:
If it is not premium mode I call this method
first I show the banner occupying 60dp assigned in design, I have added a listener so that the space is hidden if the banner cannot be loaded, but if the banner is loaded it assigns in height and width WRAP_CONTENT and shows it