我已成功获取AdMob测试广告以显示在LinearLayout中,但是如果我更改为TableLayout,它们不会显示出来。 logcat中没有显示错误。AdMob AdView不会显示在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
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银河[谷歌徽标]去旅行” 。到现在为止还挺好。但它不会出现,如果我将它更改为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”:“[URL到“应用银河测试广告]”>
广告onRecievedAd()
就是这样。没有抱怨没有足够的空间,这在其他帖子中似乎很常见。我得到的只是一个黑屏。如果我以后添加了另一个TableRow,包含一个TextView,TextView在屏幕顶部下方显示50px,就好像广告在那里一样。
有关东西的任何想法,试图让它显示出来?我已经写了一个基于TableLayout的应用程序,如果可能的话,我宁愿不必在LinearLayout中重做它。 。 。
这是我要去用,除非别人来的东西了辉煌的:放在一个LinearLayout中的AdMob广告,然后把TableLayout(应用程序,本质上)在同一个LinearLayout中。这是有效的,但是剥夺了我选择将广告放在我想要的位置 - 即,我宁愿把它放在底部而不是顶部。 (如果我在TableLayout之后添加了AdView,LinearLayout由于某种原因给了TableLayout整个屏幕,并且AdView抱怨它没有足够的空间。)设计不佳,AdView占用空间但没有显示任何内容,但没有提供任何错误。 –