如何在Andengine Base游戏活动中使用比率解析策略时覆盖onSetContentView

时间:2013-01-20 17:27:45

标签: android andengine andengine-gles-2

我正在使用andengine GLES2开发(学习构建:)游戏。 我正在使用基本游戏活动,并覆盖setContent视图以放置我的广告。
除了解决方案政策外,一切正常。
比率解决方案政策是我与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);

}

这里是我得到的图像你可以看到场景下面的白色边缘,如果你选择图像(它没有引起注意,因为堆栈溢出也有白色背景)

enter image description here

任何建议都对我很有帮助

我如何解决这个Isuue请帮帮我

感谢所有人,

1 个答案:

答案 0 :(得分:2)

FIXED:

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

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

这是我的代码

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



}