且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

显示增加了在游戏中的AndEngine Android的

更新时间:2023-02-02 19:38:43

哎呀我得到了答案,所以发布。

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


}