我正在看这个例子,但是这里的代码想要使用一些布局文件,但我的代码中没有这个...
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);
}
答案 0 :(得分:1)
您可以在GameView上方创建布局,并将GameView和AdView放入此布局中。下面的示例使用RelativeLayout并将add添加到屏幕的底部。
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);
}