AdMob AdView未显示在TableLayout中

时间:2011-09-21 22:47:51

标签: android android-layout admob

我已成功将AdMob测试广告显示在LinearLayout中,但如果我更改为TableLayout,则它们不会显示。在logcat中没有显示错误。

这是有效的:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AdRequest request = new AdRequest();
    request.setTesting(true);
    request.addTestDevice(AdRequest.TEST_EMULATOR);
    AdView adview = new AdView(this, AdSize.BANNER, [admob id deleted for posting on stackoverflow]);           
    // all code before this point is the same in both examples

    LinearLayout layout = new LinearLayout(this);
    layout.addView(adview);

    // all code after this point is the same in both examples
    this.setContentView(layout);
    adview.loadAd(request);
}

我在模拟器屏幕顶部显示一个漂亮的小横幅广告,上面写着“成功!现在您已准备好通过App Galaxy [Google徽标]”。到现在为止还挺好。但是,如果我将其更改为TableLayout,则不会出现,如下所示:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AdRequest request = new AdRequest();
    request.setTesting(true);
    request.addTestDevice(AdRequest.TEST_EMULATOR);
    AdView adview = new AdView(this, AdSize.BANNER, [admob id deleted for posting on stackoverflow]);           
    // all code before this point is the same in both examples

    TableLayout layout = new TableLayout(this);
    TableRow row = new TableRow(this);
    row.addView(adview);
    layout.addView(row);

    // all code after this point is the same in both examples
    this.setContentView(layout);
    adview.loadAd(request);
}

我在LogCat中没有错误。在这两个实例(LinearLayout或TableLayout)中,我从Admob获得的LogCat都是两条信息性消息:

  

广告已收到广告网址:<“url”:“[应用Galaxy'测试广告的网址]”>

     

广告onRecievedAd()

就是这样。没有关于没有足够空间的投诉,这在其他帖子中似乎很常见。我得到的只是黑屏。如果我之后添加另一个TableRow,包含TextView,那么TextView会在屏幕顶部下方显示50px,就像广告在那里一样。

任何关于尝试让它出现的东西的想法?我已经编写了一个基于TableLayout的应用程序,如果可能的话,我宁愿不必在LinearLayout中重做它。 。 。

1 个答案:

答案 0 :(得分:0)

我想AdView的父级应该具有以下属性:

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"