在 AndEngine Android 中显示游戏添加内容

发布于 2024-12-18 02:29:14 字数 54 浏览 3 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无妨# 2024-12-25 02:29:14

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

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


}

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


}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文