gpt4 book ai didi

android - 将 AdMob 广告添加到 RelativeLayout

转载 作者:太空狗 更新时间:2023-10-29 15:49:00 26 4
gpt4 key购买 nike

我的应用程序已完全完成。我想将我的 admob 广告添加到屏幕底部。我导入了 jar 文件等等。我只是不知道如何在屏幕底部获取广告,然后在 .java/main.xml/manifest.xml 中获取我需要的内容我尝试了一些教程,但只是强制关闭。

最佳答案

您是否从 Admob 找到了以下网站?

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

这是关于如何集成 SDK 的非常好的指南。它解释了必须在 list 、布局和代码本身中声明的内容。请务必遵循“以 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());

注意到,在单独的注释中,我认为在 Advanced 的 InterstitialAd 部分的代码示例中此站点的 Advanced 选项卡上有一个拼写错误 -

interstitialAd.loadAd(adRequest); 

应该阅读,

interstitial.loadAd(adRequest);

希望对你有帮助

关于android - 将 AdMob 广告添加到 RelativeLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6105673/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com