如何添加了AdMob的看法时,我的主要观点是这样吗? [英] How do I add the admob view when my main view is like this?

查看:151
本文介绍了如何添加了AdMob的看法时,我的主要观点是这样吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在看这个例子,但这里的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆