无法让AdMob广告显示在libgdx游戏中

时间:2014-02-23 14:01:52

标签: java android eclipse libgdx admob

我正在尝试在广告中创建一个admob横幅广告,但它没有显示出来,这就是我在logcat中获得的内容:

02-23 14:52:11.943: I/Ads(13358): Scheduling ad refresh 60000 milliseconds from now.
02-23 14:52:11.943: I/Ads(13358): Ad finished loading.
02-23 14:53:11.992: I/Ads(13358): Ad is not visible. Not refreshing ad.

在我的代码中,我使用2个屏幕,一个名为TitleScreen,一个名为GameScreen,我的游戏类名为SimonSays。

这是我在MainActivity.java中的安卓代码:

    RelativeLayout layout = new RelativeLayout(this);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    View gameView = initializeForView(new SimonSays(), true);

    AdView AdView = new AdView(this);
    AdView.setAdSize(AdSize.SMART_BANNER);
    AdView.setAdUnitId("***"); //Secret
    AdRequest.Builder adRequest = new AdRequest.Builder();
    adRequest.addTestDevice("7C4216C9F2879CE166853D136DCC4F32"); //My Galaxy S4
    AdView.loadAd(adRequest.build());

    layout.addView(gameView);

    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(AdView, adParams);

    setContentView(layout);


    initialize(new SimonSays(), cfg);

1 个答案:

答案 0 :(得分:2)

您正在初始化游戏两次。一个在这里:

View gameView = initializeForView(new SimonSays(), true);

另一个在这里:

initialize(new SimonSays(), cfg);

删除第二个,并在第一个配置中使用 cfg 配置。像这样:

RelativeLayout layout = new RelativeLayout(this);

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
View gameView = initializeForView(new SimonSays(), cfg); //<-- notice the change

AdView AdView = new AdView(this);
AdView.setAdSize(AdSize.SMART_BANNER);
AdView.setAdUnitId("***"); //Secret
AdRequest.Builder adRequest = new AdRequest.Builder();
adRequest.addTestDevice("7C4216C9F2879CE166853D136DCC4F32"); //My Galaxy S4
AdView.loadAd(adRequest.build());

layout.addView(gameView);

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(AdView, adParams);

setContentView(layout);