【问题标题】:Unable to display game screen while admob integrated with AndEngine + google play serviceadmob与AndEngine + google play服务集成时无法显示游戏画面
【发布时间】:2015-04-13 14:21:29
【问题描述】:

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

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

}

目前我可以看到游戏画面或广告。请建议如何获得游戏画面和广告。

提前致谢。

【问题讨论】:

  • 我不知道这是否会回答您的问题,但您使用的是FrameLayout,它的作用是将View 放在彼此之上,因此无论是addview 在顶部gameview 或反之亦然,而您正在使用 Fill_parent 为什么不使用 wrap_content 或一般为什么不使用 LinearLayout ?因为您的addView 的类型是Smart_Banner,所以它的高度是50dp,这是固定的。先生,我清醒了吗?

标签: android admob google-play-services andengine


【解决方案1】:

试试我用的代码:

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

}

【讨论】:

    猜你喜欢
    • 2013-06-16
    • 2014-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-11
    • 2015-01-30
    • 2014-07-08
    • 1970-01-01
    相关资源
    最近更新 更多