7

我正在开发(学习构建 :) 一款带有andengine GLES2. 我正在使用Base game activity,并覆盖setContent视图以放置我的 admob 广告。
一切正常,除了分辨率策略。
比率分辨率政策是我正在使用的政策CAMERA_WIDTH = 800; and CAMERA_HEIGHT = 480;

问题是,无论何时被覆盖,onsetContentView场景都不会与中心对齐,并且边距仅显示在底部而不是两者:顶部和底部。水平对齐时也会发生同样的情况:边距将仅显示在右侧,而不是两侧。我该如何纠正这个?我在下面给出我的代码:

@Override
protected void onSetContentView() {

    System.out.println("Content setting");
    this.mRenderSurfaceView = new RenderSurfaceView(this);


    final LayoutParams layoutParams = new LayoutParams(
            android.view.ViewGroup.LayoutParams.MATCH_PARENT,
            android.view.ViewGroup.LayoutParams.MATCH_PARENT);

    layoutParams.gravity = Gravity.LEFT ;

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

    adView = new AdView(this, AdSize.BANNER, "xxxxxxxxxxxxx");

    final FrameLayout.LayoutParams adViewLayoutParams = new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.LEFT
                    );

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

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


    this.setContentView(frameLayout, frameLayoutLayoutParams);
    this.mRenderSurfaceView.setRenderer(this.mEngine, this);

}

这是我得到的图像,如果您选择图像,您可以看到场景下方的白边(由于堆栈溢出,它没有引起注意也有白色背景)

在此处输入图像描述

任何建议都会对我很有帮助

我该如何解决这个问题请帮助我

谢谢大家,

4

1 回答 1

2

固定的:

在与布局的游戏之后,我能够解决这个问题。

现在我的表面视图与中心对齐,并且广告以所需的方式显示。

这是我的代码

@Override
protected void onSetContentView() {

    final RelativeLayout relativeLayout = new RelativeLayout(this);
    final FrameLayout.LayoutParams relativeLayoutLayoutParams = new FrameLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);

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


    final android.widget.RelativeLayout.LayoutParams surfaceViewLayoutParams = new RelativeLayout.LayoutParams(BaseGameActivity.createSurfaceViewLayoutParams());
    surfaceViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);

    relativeLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);


    FrameLayout frameLayout = new FrameLayout(this);
    adView = new AdView(this, AdSize.BANNER, "xxxxxxx");
    adView.refreshDrawableState();
    frameLayout.addView(adView);
    relativeLayout.addView(frameLayout);

    this.setContentView(relativeLayout, relativeLayoutLayoutParams);



}
于 2013-01-21T17:49:25.607 回答