在AndEngine Android中显示游戏玩法

时间:2011-11-23 04:28:20

标签: android andengine

您好我想在AndEngine的游戏顶部添加添加内容。 任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:4)

哎呀我得到了答案,所以张贴。

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


}