Adding AdMob Ad to RelativeLayout(将 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 AdMob 广告添加到 RelativeLayout


基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01