Pregunta

I'm trying to add Admob banner under game scene but some black stripe overlaps half the banner. I removed the banner to see if the problem of Admob but the stripe still there.

How can I remove it? Or is there any way to display banner over the black stripe?

Game scene with banner

Game scene without banner

Source:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId("xxxxxxxxx");

        AdRequest adRequest = new AdRequest.Builder().addTestDevice(
                AdRequest.DEVICE_ID_EMULATOR).build();

        adView.loadAd(adRequest);
        adView.setBackgroundColor(Color.BLACK);

        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        mGLSurfaceView = new CCGLSurfaceView(this);

        background = new LinearLayout(this);
        game_layout = new LinearLayout(this);
        ad_layout = new LinearLayout(this);

        background.setOrientation(LinearLayout.VERTICAL);
        ad_layout.setOrientation(LinearLayout.VERTICAL);
        game_layout.setOrientation(LinearLayout.VERTICAL);

        ad_layout.addView(adView);
        game_layout.addView(mGLSurfaceView);

        LinearLayout.LayoutParams game_params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT, 1f);
        background.addView(game_layout, game_params);

        LinearLayout.LayoutParams ad_params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        background.addView(ad_layout, ad_params);
        this.setContentView(background);
    }

    public void onStart() {
        super.onStart();
        CCDirector.sharedDirector().attachInView(mGLSurfaceView);
        CCDirector.sharedDirector().setDisplayFPS(true);
        CCDirector.sharedDirector().setAnimationInterval(1.0f / 60.0f);
        CCScene scene = GameStartLayer.scene();
        CCDirector.sharedDirector().runWithScene(scene);
    }
¿Fue útil?

Solución

I've finally found out the reason why banner was overplayed by game scene. The mistake is actually silly.

following methods must be updated:

    @Override
    public void onPause() {
        **if (adView != null) adView.pause();**
        super.onPause();
        CCDirector.sharedDirector().pause();
    }

    @Override
    public void onResume() {
        super.onResume();
        CCDirector.sharedDirector().resume();
        **if (adView != null) adView.resume();**
    }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top