2013-03-10 55 views
1

我在我的android應用程序中使用多個佈局。當我通過setContentView更改佈局時admob橫幅消失。有更改佈局時需要執行的任何操作。admob在更改佈局後消失

public void setContentView (int layoutResID) 
    { 
     super.setContentView(layoutResID); 
     // Create the adView 
     try { 
      // Lookup your LinearLayout assuming it's been given 
      // the attribute android:id="@+id/mainLayout" 

     RelativeLayout layout = (RelativeLayout) 
       findViewById(getRespectiveLayoutID(layoutResID)); 
     //adView.setGravity(Gravity.BOTTOM); 
     // Add the adView to it 
     layout.addView(adView); 

     // Initiate a generic request to load it with an ad 

    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

} 

`我真的很感激任何幫助

回答

1

當您更改佈局,您需要將廣告添加到您的新佈局。 adview是一個視圖,就像一個textview,所以你的上面的代碼正在做的是將adview添加到佈局。當您致電setContentView(R.layout.example)時,您更改了該視圖,因此無法看到廣告查看,因爲它未顯示。爲了解決這個問題,你必須把你在每次調用setContentView之後編寫的代碼放在一起。