2
我完成了我的应用程序。我想将我的admob广告添加到我的屏幕底部。我有导入的jar文件和所有。我只是无法弄清楚如何在屏幕底部获取广告,然后在.java/main.xml/manifest.xml中找到我需要的东西。我尝试了几个教程,但只是强行关闭了一些东西。将AdMob广告添加到RelativeLayout
我完成了我的应用程序。我想将我的admob广告添加到我的屏幕底部。我有导入的jar文件和所有。我只是无法弄清楚如何在屏幕底部获取广告,然后在.java/main.xml/manifest.xml中找到我需要的东西。我尝试了几个教程,但只是强行关闭了一些东西。将AdMob广告添加到RelativeLayout
您是否从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出现类似,
<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>
,更换旗帜示例代码,
// 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);
希望这会有帮助