Showing adds in gameplay in AndEngine Android

时间秒杀一切 提交于 2019-12-06 14:13:55

问题


Hi I want to show adds at the top of the game in AndEngine. Can any one help me with this??


回答1:


Oops I got the answer so posting.

@Override
protected void onSetContentView() {

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

    final AdView adView = new AdView(this, AdSize.BANNER, "XXXXXXXXXXXXXXXXX");
    adView.refreshDrawableState();
    adView.setVisibility(AdView.VISIBLE);
    final FrameLayout.LayoutParams adViewLayoutParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                                         FrameLayout.LayoutParams.WRAP_CONTENT,
                                         Gravity.CENTER_HORIZONTAL);
/*    
    int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50,
            getResources ().getDisplayMetrics ());*/
    // top of AD is at middle of the screen
    adViewLayoutParams.topMargin = 0;

    AdRequest adRequest = new AdRequest();
    adRequest.addTestDevice( AdRequest.TEST_EMULATOR);
    adView.loadAd(adRequest);

    this.mRenderSurfaceView = new RenderSurfaceView(this);
    mRenderSurfaceView.setRenderer(mEngine);

    final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams =
            new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());

    frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
    frameLayout.addView(adView, adViewLayoutParams);

    this.setContentView(frameLayout, frameLayoutLayoutParams);


}


来源:https://stackoverflow.com/questions/8237346/showing-adds-in-gameplay-in-andengine-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!