将AdMob广告添加到RelativeLayout [英] Adding AdMob Ad to RelativeLayout

查看:87
本文介绍了将AdMob广告添加到RelativeLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have my app completely done. I want to add my admob ad to the bottom of my screen. I have the jar file imported and all that. I just cannot figure out how to get the ad at the bottom of the screen then what I need in the .java/main.xml/manifest.xml I tried a few tutorials but just got a force close.

推荐答案

您是否已从Admob找到以下站点?

Have you found the following site from Admob?

http://code.google.com/mobile/ads/docs/android/fundamentals.html

这是有关如何集成SDK的非常好的指南。它解释了清单,布局和代码本身必须声明的内容。确保遵循以XML创建横幅。本页上的链接-这将向您展示如何设置主XML。

This is a really good guide on how to integrate the sdk. It explains what must be declared in the manifest, layout and code itself. Be sure to follow the "create your banner in XML." Link on this page - this will show you how to setup your main xml. Where it states,

<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" 

将广告定位在布局的底部。因此,如果您使用相对布局,则会显示以下内容,

to position the ad at the bottom of the layout. So if your using a relative layout it will appear something like,

 <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,因此将标语示例代码替换为

Because you are using RelativeLayout, replace the banner example code with,

 // 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部分-

Noticed, on a seperate note I think there is a typo on the Advanced tab for this site in the code sample at the InterstitialAd section of Advanced -

interstitialAd.loadAd(adRequest); 

应阅读,

interstitial.loadAd(adRequest);

希望这会有所帮助

这篇关于将AdMob广告添加到RelativeLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆