如何添加了AdMob的看法时,我的主要观点是这样吗? [英] How do I add the admob view when my main view is like this?
问题描述
我在看这个例子,但这里的code要使用一些布局文件,但是我没有,在我的code ..
的http:// code.google.com/intl/da/mobile/ads/docs/android/fundamentals.html
我的行为看起来是这样的。我不知道如何对AdMob的视图添加到我这里使用的视图。
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
GameView VW =新GameView(这一点,intDpi);
的setContentView(VW);
}
您可以创建上述GameView布局,把GameView和AD浏览报这个布局。下面的例子使用一个RelativeLayout的,并把附加在屏幕的底部。
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
RelativeLayout的布局=新RelativeLayout的(这一点);
GameView VW =新GameView(这一点,intDpi);
layout.addView(VW);
AD浏览报=新的AD浏览报(这一点,AdSize.BANNER,YOUR_AD_UNIT_ID);
//在屏幕底部的地方AD浏览报。
RelativeLayout.LayoutParams PARAMS =
新RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,RelativeLayout.TRUE);
layout.addView(AD浏览报);
adView.loadAd(新AdRequest());
的setContentView(布局);
}
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);
}
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);
}
这篇关于如何添加了AdMob的看法时,我的主要观点是这样吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!