2011-05-24 63 views
2

我完成了我的應用程序。我想將我的admob廣告添加到我的屏幕底部。我有導入的jar文件和所有。我只是無法弄清楚如何在屏幕底部獲取廣告,然後在.java/main.xml/manifest.xml中找到我需要的東西。我嘗試了幾個教程,但只是強行關閉了一些東西。將AdMob廣告添加到RelativeLayout

回答

9

您是否從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); 

希望這會有幫助

相關問題