2011-05-10 36 views
0

我創建了一個遊戲,它具有從surfaceView派生的自定義視圖。並且在遊戲中我想將adView放置在gameView下方。但問題是,如果我把AD瀏覽的gameView下方,AdView中不會顯示出來..我所有的布點中的代碼,因爲它更易於維護..如何在下面放置adView?

這裏是代碼..

如果我放在上面gameView AD瀏覽它會顯示

private RelativeLayout layout; //the gameView container 
private LinearLayout mainLayout; //the main layout 
private RocketView rocketView; //the gameView 
private AdView adView;    //the adView 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

     mainLayout = new LinearLayout(this); 
     mainLayout.setOrientation(LinearLayout.VERTICAL); 

     adView = new AdView(this, AdSize.BANNER, "a14d9e9ea3740e8"); 
     adView.setVisibility(AdView.VISIBLE); 
     adView.loadAd(new AdRequest()); 
     mainLayout.addView(adView); // -->> here i place the adView first 

     layout = new RelativeLayout(this); 
     mainLayout.addView(layout); //--->> then i place the gameView later 

     rocketView = new RocketView(this); 
     layout.addView(rocketView); 
     setContentView(mainLayout); 
} 

但如果我把它下面的AdView中不會出現。

private RelativeLayout layout; 
private LinearLayout mainLayout; 
private RocketView rocketView; 
private Launcher launcher; 

private AdView adView; 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
     mainLayout = new LinearLayout(this); 
     mainLayout.setOrientation(LinearLayout.VERTICAL); 

     layout = new RelativeLayout(this); 
     mainLayout.addView(layout); 

     rocketView = new RocketView(this); 
     layout.addView(rocketView); 

     adView = new AdView(this, AdSize.BANNER, "a14d9e9ea3740e8"); 
     adView.setVisibility(AdView.VISIBLE); 
     adView.loadAd(new AdRequest()); 
     mainLayout.addView(adView); 
     setContentView(mainLayout); 

} 

我想我知道發生什麼事.. AD瀏覽加載AdRequest中之後,並獲得廣告,它不是streching以上,但低於streching,所以它不會在屏幕上顯示。但我不知道如何解決這個問題。請幫助我..

回答

2

首先,不需要線性佈局mainLayout。將rocketView和adView添加到您的relativelayout佈局。給予adView屬性align_parent_bottom,wrap_content(height)和wrap_content或fill_parent的寬度。然後給rocketView fill_parent的寬度和高度,並使其位於adView的「上方」。

+0

當你完成時,不要忘記更改setContentView()的參數。 – Amplify91 2011-05-10 15:41:46

+0

如何將屬性賦予adView? – Fugogugo 2011-05-10 15:48:01

+0

無論如何,如果我不使用線性佈局,廣告會阻止某些視圖。這就是爲什麼我使用 – Fugogugo 2011-05-10 15:48:54

相關問題