【问题标题】:Empty space after AdMob disappearAdMob 消失后的空白空间
【发布时间】:2012-10-10 22:05:23
【问题描述】:

我有布局结构:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >
  <com.google.ads.AdView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   ads:adSize="BANNER"
  />
    
  <LinearLayout style="@style/TitleBar"
   android:layout_width="fill_parent"
   android:layout_height="45dip"
    // title bar
  </LinearLayout>
  
<RelativeLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  // main layout with all needed elements and background!" >
  
</RelativeLayout>
</LinearLayout>

一切看起来都很好,直到我的 AdMob 消失了。然后我可以看到带有 admob 大小的空白黑色区域。

更新:我的屏幕截图:

通常我会在这里看到广告块,但是当我收到 onFailedToReceiveAd(广告请求成功,但由于缺少广告库存而没有返回广告。)广告消散并且我的布局没有填满整个屏幕。

【问题讨论】:

  • “AdMob 消失”是什么意思?什么时候消失?
  • 布局看起来不错,因为 admob 第一次显示。当广告显示时,所有元素都向下移动,但仍然看起来像我想要的那样。但是当广告消失时,我的布局并没有向上移动(到原始状态)。
  • 能发个截图吗?我这么说是因为 admob 这个月遇到了问题。有点像这种视觉效果。
  • 允许应用在没有可用的 admob 应用时接收谷歌广告。您可以在 Admob 应用设置中执行此操作。

标签: android layout


【解决方案1】:

你的描述看起来很奇怪...... 我认为导致广告消失的原因是,如果广告被刷新,然后由于 AdMob 端缺少广告而没有提供广告。 但是根据我自己的测试,一旦加载了广告,如果后续的广告刷新失败,之前的广告仍然显示,我没有看到广告“消失”。

也许你可以看看 logcat 看看是否有任何错误。

这是我用来在自己的应用上测试广告请求交付/失败的一些代码。 如果广告加载失败后出现空白,我想您可以在 onFailedToReceiveAd 中放置一些代码来调整 AdView 的大小

AdView av = (AdView)findViewById(R.id.adView);

        // Set AdListener
        av.setAdListener(new AdListener() {
            AdView av = (AdView)findViewById(R.id.adView);
            @Override
            public void onFailedToReceiveAd(Ad ad, ErrorCode error) {
                System.err.println("Ad failed: " + ad.toString() + error.toString());
                av.setVisibility(AdView.GONE);//By setting visibility to GONE, you hide the AdView, but the AdView won't refresh automaticaly anymore.

            }

            @Override
            public void onReceiveAd(Ad ad) {
                System.out.println("Ad received: " + ad.toString());
                av.setVisibility(AdView.VISIBLE);
            }
        });

        // Create an ad request.
        AdRequest adRequest = new AdRequest();

        // Start loading the ad in the background.
        av.loadAd(adRequest);

【讨论】:

  • 您的最新更新证实了我的想法,您收到广告失败,因为 AdMob 没有任何广告可投放。您使用的是什么版本的 AdMob SDK(我使用的是 4.1.0)?我很好奇,因为我的应用程序的行为似乎有所不同,当我在广告刷新时遇到失败,而不是空白空间,之前的广告会留在显示上。现在,对于 AdMob 没有足够的广告投放,您无能为力,您可以在 onFailedToReceiveAd 中添加一些代码来强制发出新的广告请求,尝试隐藏 AdView 并在 onReceiveAd 中再次显示它,或者设置一个内部广告来填充虚无。
  • 我已经添加了一些代码来隐藏 AdView 以防失败,这里的缺点是当使用 setVisibility(GONE) 隐藏时,AdView 不会再刷新,所以你应该手动执行 @987654323 @ 在某一点。一旦 loadAd 成功,setVisibility(VISIBLE) 内的 onReceiveAd 将再次显示 AdView,此后它将根据 AdMob 设置刷新。
  • 请注意,在当前的 admob sdk play-services-ads:15.0.0 中,通过 INVISIBLE 或 GONE 隐藏 adview,将阻止它再次加载广告
【解决方案2】:

只是为了确认您的 adView 是否有此作为高度参数?

android:layout_height="wrap_content"

【讨论】:

  • 这是为了确保您在设置 AdMob 时不会在 xml 或代码中为布局提供绝对大小。
【解决方案3】:

查看此问题的另一种方法是在 AdMob 中设置您自己的“自家广告”来定位您的应用。然后,当 AdMob 没有要投放的广告时,它会展示您自己的广告以“填补空白”。

【讨论】:

  • 好主意!我会考虑这个解决方案。
【解决方案4】:

使用设置可见性功能将其从布局中删除。

SetVisibility()

Check this post also on hiding the AdView

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-20
    • 1970-01-01
    • 2011-10-30
    相关资源
    最近更新 更多