将AdMob广告添加到RelativeLayout

问题描述

| 我已经完成我的应用程序。我想将我的admob广告添加到屏幕底部。我已经导入了jar文件。我只是无法弄清楚如何在屏幕底部获取广告,然后在.java / main.xml / manifest.xml中获取所需的内容,我尝试了一些教程,但很快就关闭了。     

解决方法

您是否已从Admob找到以下站点? http://code.google.com/mobile/ads/docs/android/fundamentals.html 这是有关如何集成sdk的非常好的指南。它解释了清单,布局和代码本身必须声明的内容。确保遵循此页面上的“使用XML创建横幅广告。”链接-这将向您展示如何设置主XML。注明的地方
<com.google.ads.AdView android:id=\"@+id/adView\"
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
ads:adUnitId=\"MY_AD_UNIT_ID\"                          
ads:adSize=\"BANNER\"                         
ads:loadAdOnCreate=\"true\"/>
只需添加标签,
android:layout_alignParentBottom=\"true\" 
将广告定位在布局的底部。因此,如果您使用相对布局,则会显示类似以下内容的内容,
 <RelativeLayout
    android:layout_width=\"fill_parent\"
    android:layout_height=\"fill_parent\" >
    <com.google.ads.AdView  
      android:id=\"@+id/ad\" 
      android:layout_width=\"fill_parent\" 
      android:layout_height=\"wrap_content\"
      android:layout_alignParentBottom=\"true\"
      ads:backgroundColor=\"#000000\"
      ads:adUnitId=\"<Your Ad Unit ID>\"
      ads:primaryTextColor=\"#FFFFFF\"
      ads:secondaryTextColor=\"#CCCCCC\"
      ads:adSize=\"BANNER\"
    />
</RelativeLayout>
由于您使用的是RelativeLayout,因此将横幅示例代码替换为,
 // Create the adView     
AdView adView = new AdView(this,AdSize.BANNER,MY_AD_UNIT_ID);     
// Lookup your RelativeLayoutLayout assuming it’s been given     
// the attribute android:id=\"@+id/ad\"     
RelativeLayoutlayout = (RelativeLayout)findViewById(R.id.ad);     
// Add the adView to it
layout.addView(adView);     
// Initiate a generic request to load it with an ad     
adView.loadAd(new AdRequest());
请注意,另外,我认为此网站的“高级”标签上有一个错字,位于“高级”的InterstitialAd部分的代码示例中-
interstitialAd.loadAd(adRequest); 
应该读,
interstitial.loadAd(adRequest);
希望这可以帮助     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...