admob 与 AndEngine + google play 服务集成时无法显示游戏画面 [英] Unable to display game screen while admob integrated with AndEngine + google play service

查看:24
本文介绍了admob 与 AndEngine + google play 服务集成时无法显示游戏画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 andengine 通过 google play 服务进行游戏开发,我的游戏运行良好.但是一旦我添加了带有onSetContentView"回调的 admob,我的游戏屏幕就会变黑,只有广告可见.这是我的回调 onSetContentView 函数:

I am using andengine for my game development with google play services, my game works fine. But once I added admob with "onSetContentView" callback called, my game screen goes black and only ads are visible. Here is my callback onSetContentView function:

@override
protected void onSetContentView() {
    this.mRenderSurfaceView = new RenderSurfaceView(this);
    this.mRenderSurfaceView.setRenderer(mEngine, this);
    final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams = new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());
    Log.i(TAG,"In funcion OnSetContaitView");
    //Creating the banner view.
    AdView adView = new AdView(this);
    adView.setAdSize(com.google.android.gms.ads.AdSize.BANNER);
    adView.setAdUnitId("my adunit id");

    //create add req
    AdRequest adRequest = new AdRequest.Builder()
         .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)// This is for emulators
          //test mode on DEVICE (this example code must be replaced with your device uniquq ID)
         .addTestDevice("2EAB96D84FE62876379A9C030AA6A0AC") // Nexus 5
         .addTestDevice("TA93303NP9")
         .build();


    adView.loadAd(adRequest);
    final FrameLayout.LayoutParams adViewLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);


    final FrameLayout frameLayout = new FrameLayout(this);
    final FrameLayout.LayoutParams frameLayoutLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT);

    frameLayout.addView(this.mRenderSurfaceView,surfaceViewLayoutParams);
    frameLayout.addView(adView,adViewLayoutParams);
    this.setContentView(frameLayout, frameLayoutLayoutParams);
    adView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

}

目前我可以看到游戏屏幕或广告.请建议如何获得游戏屏幕和广告.

Currently I am able to see either game screen or ads. Please suggest how to get game screen along with ads.

提前致谢.

推荐答案

试试我用的代码:

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

    setContentView(R.layout.activity_main);

    final DisplayMetrics displayMetrics = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);


    this.adView = new AdView(this);
    this.adView.setAdSize(com.google.android.gms.ads.AdSize.SMART_BANNER);
    this.adView.setAdUnitId("PUT YOUR NUMBER");
    com.google.android.gms.ads.AdRequest adrequest = new com.google.android.gms.ads.AdRequest.Builder().build(); //you can use test device as you did in your code


    this.adView.loadAd(adrequest);

    RelativeLayout layout = (RelativeLayout)findViewById(R.id.relativeLayout);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);


    layout.addView(this.mRenderSurfaceView);



    layout.addView(this.adView, params);

}

这篇关于admob 与 AndEngine + google play 服务集成时无法显示游戏画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆