问题
I'm looking at this example, but here the code wants to use some layout file, but I dont have that in my code..
http://code.google.com/intl/da/mobile/ads/docs/android/fundamentals.html
My activity looks like this.. I have no clue how to add the admob view to the view I use here..
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GameView vw = new GameView( this, intDpi );
setContentView(vw);
}
回答1:
You can create a layout above the GameView and put the GameView and the AdView into this layout. The below example uses a RelativeLayout and puts the add at the bottom of the screen.
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);
}
来源:https://stackoverflow.com/questions/9300459/how-do-i-add-the-admob-view-when-my-main-view-is-like-this