随笔 - 79  文章 - 58  trackbacks - 0
<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(9)

随笔分类

随笔档案

文章档案

相册

搜索

  •  

积分与排名

  • 积分 - 294191
  • 排名 - 87

最新评论

阅读排行榜

评论排行榜

摘自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 阅读(984) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理