我正在使用cocos2dx JS 3.0,我正在尝试直接在Android中实现Admob,而无需通过cocos2dx调用。
创建AdUnit并按如下方式实施AdView:
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("AC2DFFFAFB44FE1EBC80F6B40559AB14")
.build();
AdView adView = new AdView(AppActivity.this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-XYZ/XYZ");
adView.loadAd(request);
@SuppressWarnings("deprecation")
ViewGroup.LayoutParams ad_layout_params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
adView.setLayoutParams(ad_layout_params);
mFrameLayout.addView(adView); //Here `mFrameLayout` is the core `RelativeLayout` that contains GLView's that run cocos engine.
在Logcat中,我得到以下内容,但AD未显示!!
Starting ad request.
JS: [Some JS Logs]
Ad finished loading.
Scheduling ad refresh 60000 milliseconds from now.
Ad is not visible. Not refreshing ad.
Scheduling ad refresh 60000 milliseconds from now.
Ad is not visible. Not refreshing ad.
Scheduling ad refresh 60000 milliseconds from now.
Ad is not visible. Not refreshing ad.
[repeating]
我想,admob集成是正确的,但是将AdView添加到正确的父视图或设置AdView的位置时出现问题。
根据此帖子(Move AdView to bottom, Cocos2dx Activity),将mFrameLayout
中的Cocos2dxActivity
更改为RelativeLayout
任何帮助都将受到高度赞赏!!
答案 0 :(得分:1)
解决了问题......: - )
glSurfaceView
返回的onCreateView
已添加到超类mFrameLayout
中的Cocos2dxActivity
,因此接管adview
...
因此,
AdView
,Cocos2dxActivity
中,
glSurfaceView
添加到mFrameLayout
代码:
onCreateView我们的活动:
AdRequest request = new AdRequest.Builder()
.build();
AdView adView = new AdView(AppActivity.this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-XYZ");
adView.setId(999);
adView.loadAd(request);
@SuppressWarnings("deprecation")
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
adView.setLayoutParams(params);
mFrameLayout.addView(adView);
在frameworks / js-bindings / cocos2d -x / cocos / platform / android / java / src / org / cocos2dx / lib / Cocos2dxActivity.java:190 init
函数结束,
mFrameLayout.bringChildToFront(mFrameLayout.findViewById(999));