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

查看:19
本文介绍了将 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天全站免登陆