7

私はでゲームを開発しています(構築することを学んでいます:) andengine GLES2Baseゲームアクティビティを使用しており、ビューをオーバーライドし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 に答える