将AdView移至底部,Cocos2dx活动

时间:2014-08-01 22:45:56

标签: java android cocos2d-x

请帮助我将广告移至屏幕底部

Cocos2dxActivity.this.adView = new AdView(Cocos2dxActivity.this, AdSize.SMART_BANNER, mediationId());

                    @SuppressWarnings("deprecation")
                    ViewGroup.LayoutParams ad_layout_params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);                        


                    Cocos2dxActivity.this.adView.setLayoutParams(ad_layout_params);

                    AdRequest adRequest = new AdRequest();

1 个答案:

答案 0 :(得分:2)

注意:这与cocos2d-x 3.1.1有关,尽管早期版本应与此类似。

Cocos2dxActivity使用FrameLayout作为其最顶层布局。为了达到你想要的效果,这已经改为RelativeLayout - 在Cocos2dxActivity类中,你应该编辑一个init()方法。还有一个名为mFrameLayout的类变量 - 只需将其类型更改为RelativeLayout并相应地命名,您的IDE应该告诉您还有哪些地方可以更改。

关于横幅本身,在将其添加到RelativeLayout时,应该给它这个布局参数:

RelativeLayout.LayoutParams relParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
relParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
relParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);