随笔 - 79  文章 - 58  trackbacks - 0
<2016年7月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(9)

随笔分类

随笔档案

文章档案

相册

搜索

  •  

积分与排名

  • 积分 - 283046
  • 排名 - 85

最新评论

阅读排行榜

评论排行榜

摘自http://code.google.com/p/libgdx/wiki/AdMobInLibgdx

libgdx初始化的方式一般如下:

public class HelloWorldAndroid extends AndroidApplication { 

   
@Override public void onCreate (Bundle savedInstanceState) { 

       
super.onCreate(savedInstanceState); 

        initialize
(new HelloWorld(), false);             

   
} 

}

initialize中封装了初始化view:

       requestWindowFeature(Window.FEATURE_NO_TITLE); 

       getWindow
().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

       getWindow
().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); 

       setContentView
(graphics.getView(), createLayoutParams()); 

为了将广告的view植入进去,不能使用initialize,使用initializeForView,这里以多盟为例如下:

 

public class HelloWorldAndroid extends AndroidApplication { 

   
@Override public void onCreate (Bundle savedInstanceState) { 

       
super.onCreate(savedInstanceState); 

        //initialize
(new HelloWorld(), false);             

        // Create the layout
        RelativeLayout layout = new RelativeLayout(this);
 
        // Do the stuff that initialize() would do for you
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        // Create the libgdx View
        View gameView = initializeForView(new RabbitGame(this), false);

        // Add the libgdx view
        layout.addView(gameView);
       

        //初始化广告视图
        DomobAdView mAdview320x50 = new DomobAdView(this, "56OJyM1ouMGoaSnvCK", DomobAdView.INLINE_SIZE_320X50);

        RelativeLayout.LayoutParams adParams = 
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                            RelativeLayout.LayoutParams.WRAP_CONTENT);
        adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
   
       
        layout.addView(mAdview320x50, adParams);
        // Hook it all up
        setContentView(layout);


    } 

}

 

posted on 2012-08-05 11:28 merlinfang 阅读(915) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理