2012-02-15 49 views
0

我期待在這個例子中,但這裏的代碼要使用一些佈局文件,但我沒有在我的代碼..當我的主視圖是這樣的時候,如何添加admob視圖?

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

我的活動是這樣的..我有沒有線索如何將admob視圖添加到此處使用的視圖中。

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    GameView vw = new GameView(this, intDpi); 

    setContentView(vw); 

} 

回答

1

您可以在GameView上方創建佈局,並將GameView和AdView放入此佈局。以下示例使用RelativeLayout並將添加放置在屏幕的底部。

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    RelativeLayout layout = new RelativeLayout(this); 
    GameView vw = new GameView(this, intDpi); 
    layout.addView(vw); 

    adView = new AdView(this, AdSize.BANNER, "YOUR_AD_UNIT_ID"); 
    // Places adView at bottom of screen. 
    RelativeLayout.LayoutParams params = 
     new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
             RelativeLayout.LayoutParams.WRAP_CONTENT); 
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); 
    layout.addView(adView); 
    adView.loadAd(new AdRequest()); 

    setContentView(layout); 
} 
相關問題