Android:虽然日志显示广告已加载,但AdView未显示

时间:2014-10-19 12:48:34

标签: android admob cocos2d-x cocos2d-x-3.0

我正在使用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

任何帮助都将受到高度赞赏!!

1 个答案:

答案 0 :(得分:1)

解决了问题......: - )

glSurfaceView返回的onCreateView已添加到超类mFrameLayout中的Cocos2dxActivity,因此接管adview ...

因此,

  • 将一些标记(999)分配给此处的AdView
  • 在超级班Cocos2dxActivity中,
    • glSurfaceView添加到mFrameLayout
    • 带有标签999(我们的广告)的孩子被带到前面..

代码:

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));